Workaround for memory leak in flex.
authorPeter Verthez <Peter.Verthez@advalvas.be>
Sat, 21 Sep 2002 20:06:39 +0000 (20:06 +0000)
committerPeter Verthez <Peter.Verthez@advalvas.be>
Sat, 21 Sep 2002 20:06:39 +0000 (20:06 +0000)
gedcom/gedcom_1byte.lex
gedcom/gedcom_hilo.lex
gedcom/gedcom_lex_common.c
gedcom/gedcom_lohi.lex

index 6431dcfdcbdae061043c5947331fd376c1b7d9f1..6fa1d6b0293089b3f4573f8482d7ecd1e1d6eb4e 100644 (file)
@@ -216,8 +216,12 @@ ACTION_BEFORE_REGEXPS
 
 %%
 
+static int exitfuncregistered = 0;
+
 int yywrap()
 {
+  if (! exitfuncregistered && atexit(yylex_cleanup) == 0)
+    exitfuncregistered = 1;
   return 1;
 }
 
index c7a715133d8f596fa43f1f56d3c91b8a4d634a86..a5216bb7561343014e8a648a81844722c27c411a 100644 (file)
@@ -219,8 +219,12 @@ ACTION_BEFORE_REGEXPS
 
 %%
 
+static int exitfuncregistered = 0;
+
 int yywrap()
 {
+  if (! exitfuncregistered && atexit(yylex_cleanup) == 0)
+    atexit(yylex_cleanup);
   return 1;
 }
 
index 3785da2a8960d7bec5cd88a92e3bcf87f93450f3..045cea22d3ba46e2bb3c64500efafe5c784263d1 100644 (file)
@@ -136,6 +136,13 @@ static void error_unexpected_character(const char* str, char ch)
   gedcom_error(_("Unexpected character: '%s' (0x%02x)"), str, ch);
 }
 
+static void yylex_cleanup()
+{
+  /* fix memory leak in lex */
+  yy_delete_buffer(yy_current_buffer);
+  yy_current_buffer = NULL;
+}
+
 #else  /* of #ifndef IN_LEX */
 
 #define TO_INTERNAL(STR,OUTBUF) \
index d6092a6d67d158c3bb2e9a8c7baf27b53dc72826..a2f82a96cd361f8ba4d89330fe13180f2eb57b5c 100644 (file)
@@ -219,8 +219,12 @@ ACTION_BEFORE_REGEXPS
 
 %%
 
+static int exitfuncregistered = 0;
+
 int yywrap()
 {
+  if (! exitfuncregistered && atexit(yylex_cleanup) == 0)
+    atexit(yylex_cleanup);
   return 1;
 }