fix: codegen O(n²) HTML memory leak + elb stderr surface + runtime dir path

This commit is contained in:
Will Anderson
2026-05-05 14:40:15 -05:00
parent 962c8cbe57
commit 7f295bffe9
5 changed files with 87 additions and 27 deletions
+28
View File
@@ -1887,6 +1887,34 @@ el_val_t fs_write_bytes(el_val_t pathv, el_val_t bytesv, el_val_t lengthv) {
return 1;
}
// stdout_to_file / stdout_restore — redirect process stdout to a file and
// restore it. Used by the compiler's JS post-processing pipeline to capture
// codegen output before piping through terser / obfuscator.
#include <fcntl.h>
static int _el_saved_stdout_fd = -1;
el_val_t stdout_to_file(el_val_t pathv) {
const char* path = EL_CSTR(pathv);
if (!path) return (el_val_t)(int64_t)-1;
fflush(stdout);
_el_saved_stdout_fd = dup(STDOUT_FILENO);
int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0600);
if (fd < 0) return (el_val_t)(int64_t)-1;
dup2(fd, STDOUT_FILENO);
close(fd);
return (el_val_t)(int64_t)0;
}
el_val_t stdout_restore(void) {
if (_el_saved_stdout_fd >= 0) {
fflush(stdout);
dup2(_el_saved_stdout_fd, STDOUT_FILENO);
close(_el_saved_stdout_fd);
_el_saved_stdout_fd = -1;
}
return (el_val_t)(int64_t)0;
}
// exec_command — run a shell command, return exit code (0 = success).
// Used by elb and other El tooling to invoke subprocesses.
el_val_t exec_command(el_val_t cmdv) {