From a3b0cfbc739c96d2d5608c6acee78786c4e5232c Mon Sep 17 00:00:00 2001 From: Matthias Andree Date: Sun, 6 Mar 2005 01:05:36 +0000 Subject: Fix memory leak. svn path=/trunk/; revision=4018 --- rcfile_l.l | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'rcfile_l.l') diff --git a/rcfile_l.l b/rcfile_l.l index b50ac617..7cd26d03 100644 --- a/rcfile_l.l +++ b/rcfile_l.l @@ -31,20 +31,18 @@ int prc_lineno = 1; %% \"[^\"]*\" { - char buf[MSGBUFSIZE]; - yytext[strlen(yytext)-1] = '\0'; - escapes(yytext+1, buf); - yylval.sval = (char *) xstrdup(buf); + escapes(yytext+1, yytext); + yyleng = strlen(yytext); + yylval.sval = yytext; SETSTATE(0); return STRING; } \'[^\']*\' { - char buf[MSGBUFSIZE]; - yytext[strlen(yytext)-1] = '\0'; - escapes(yytext+1, buf); - yylval.sval = (char *) xstrdup(buf); + escapes(yytext+1, yytext); + yyleng = strlen(yytext); + yylval.sval = yytext; SETSTATE(0); return STRING; } @@ -52,10 +50,9 @@ int prc_lineno = 1; "*" { BEGIN(0); return WILDCARD; } [^=;:, \t\r\n]+ { - char buf[MSGBUFSIZE]; - - escapes(yytext, buf); - yylval.sval = (char *) xstrdup(buf); + escapes(yytext, yytext); + yyleng = strlen(yytext); + yylval.sval = yytext; SETSTATE(0); return STRING; } @@ -204,10 +201,9 @@ options {/* EMPTY */} -?[0-9]+ { yylval.number = atoi(yytext); return NUMBER; } [^=;:, \t\r\n]+ { - char buf[MSGBUFSIZE]; - - escapes(yytext, buf); - yylval.sval = (char *) xstrdup(buf); + escapes(yytext, yytext); + yyleng = strlen(yytext); + yylval.sval = yytext; return STRING; } @@ -216,7 +212,9 @@ options {/* EMPTY */} %% void escapes(cp, tp) -/* process standard C-style escape sequences in a string */ +/* process standard C-style escape sequences in a string, + * this can never lengthen the output, so cp and tp may overlap as long + * as cp >= tp. */ const char *cp; /* source string with escapes */ char *tp; /* target buffer for digested string */ { @@ -259,4 +257,3 @@ char *tp; /* target buffer for digested string */ } *tp = '\0'; } - -- cgit v1.2.3