1
0
Fork 0
mirror of https://github.com/rubyjs/mini_racer synced 2023-03-27 23:21:28 -04:00
mini_racer/ext
Sam Saffron 0752264620
rb_heap_snapshot: fix memory leak from fdopen
The result of fdopen(3) must be matched with fclose(3) to
avoid memory leaks.  However, fclose(3) has the side-effect
of closing the underlying FD behind Ruby's back (which would
corrupt Ruby's internals and cause problems for the remainder
of the process lifetime).

While one could dup(fptr->fd) to fdopen+fclose the resulting fd,
it would cause problems on FD-constrained systems.  Since
GetChunkSize() is available and returns a reasonable value
(64K), the buffering of fwrite(3) is unnecessary and we can
safely use write(2) without performance loss.

So use unbuffered write(2) and perhaps prepare us for better
error reporting in a future change.

I've verified WriteAsciiChunk is indeed receiving the requested
64K (or close to it) in nearly all cases, so excessive syscalls
should not be a problem.
2021-12-08 16:17:36 +11:00
..
mini_racer_extension rb_heap_snapshot: fix memory leak from fdopen 2021-12-08 16:17:36 +11:00
mini_racer_loader