From: Peter Verthez Date: Sat, 21 Sep 2002 20:06:39 +0000 (+0000) Subject: Workaround for memory leak in flex. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=e6cd9cd58e0e23f70e75b140d16354af665d7b43;p=gedcom-parse.git Workaround for memory leak in flex. --- diff --git a/gedcom/gedcom_1byte.lex b/gedcom/gedcom_1byte.lex index 6431dcf..6fa1d6b 100644 --- a/gedcom/gedcom_1byte.lex +++ b/gedcom/gedcom_1byte.lex @@ -216,8 +216,12 @@ ACTION_BEFORE_REGEXPS %% +static int exitfuncregistered = 0; + int yywrap() { + if (! exitfuncregistered && atexit(yylex_cleanup) == 0) + exitfuncregistered = 1; return 1; } diff --git a/gedcom/gedcom_hilo.lex b/gedcom/gedcom_hilo.lex index c7a7151..a5216bb 100644 --- a/gedcom/gedcom_hilo.lex +++ b/gedcom/gedcom_hilo.lex @@ -219,8 +219,12 @@ ACTION_BEFORE_REGEXPS %% +static int exitfuncregistered = 0; + int yywrap() { + if (! exitfuncregistered && atexit(yylex_cleanup) == 0) + atexit(yylex_cleanup); return 1; } diff --git a/gedcom/gedcom_lex_common.c b/gedcom/gedcom_lex_common.c index 3785da2..045cea2 100644 --- a/gedcom/gedcom_lex_common.c +++ b/gedcom/gedcom_lex_common.c @@ -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) \ diff --git a/gedcom/gedcom_lohi.lex b/gedcom/gedcom_lohi.lex index d6092a6..a2f82a9 100644 --- a/gedcom/gedcom_lohi.lex +++ b/gedcom/gedcom_lohi.lex @@ -219,8 +219,12 @@ ACTION_BEFORE_REGEXPS %% +static int exitfuncregistered = 0; + int yywrap() { + if (! exitfuncregistered && atexit(yylex_cleanup) == 0) + atexit(yylex_cleanup); return 1; }