# New Ticket Created by Nick Glencross
# Please include the string: [perl #37635]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=37635 >
This patch closes filehandles which are being leaked by imcc.
Closing filehandles is obviously a good thing, but particularly
manifests itself on platforms such as HP-UX where the ulimit on file
descriptors is set quite low (typically 50). Compiling tclllib.pbc
currently typically opens >80 file descriptors concurrently (and blows
up on HP-UX).
NOTE: imcc/imclexer.c will need to be recreated after patching
Regards,
Nick
Index: imcc/imc.h
===================================================================
--- imcc/imc.h (revision 9840)
+++ imcc/imc.h (working copy)
@@ -166,6 +166,7 @@
struct parser_state_t *next;
Interp *interpreter;
const char *file;
+ FILE *handle;
int line;
int pasm_file; /* pasm_file mode of this frame */
int pragmas; /* n_operators ... */
Index: imcc/imcc.l
===================================================================
--- imcc/imcc.l (revision 9840)
+++ imcc/imcc.l (working copy)
@@ -611,6 +611,7 @@
tmp = mem_sys_allocate_zeroed(sizeof(struct macro_frame_t));
tmp->label = ++label;
tmp->s.line = line;
+ tmp->s.handle = NULL;
if (frames) {
tmp->s.pasm_file = frames->s.pasm_file;
tmp->s.file = frames->s.file;
@@ -922,7 +923,9 @@
}
else
IMCC_fataly(interp, E_IOError, strerror(errno));
+
frame->s.file = file_name;
+ frame->s.handle = file;
ext = strrchr(file_name, '.');
if (ext) {
@@ -970,6 +973,7 @@
struct macro_frame_t *tmp;
tmp = frames;
if (tmp) {
+ if (tmp->s.handle) fclose (tmp->s.handle);
frames = (struct macro_frame_t*) frames->s.next;
destroy_frame(tmp);
}