From: Todd C. Miller Date: Thu, 10 Apr 2008 15:28:10 +0000 (+0000) Subject: Clean up some memory leaks pointed out by valgrind. X-Git-Tag: SUDO_1_7_0~127 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b06e2f9d65989bfe3e945b679c4d33061fd96d08;p=sudo Clean up some memory leaks pointed out by valgrind. --- diff --git a/alias.c b/alias.c index 0e12a0f92..6179294d9 100644 --- a/alias.c +++ b/alias.c @@ -43,6 +43,7 @@ #include "sudo.h" #include "parse.h" #include "redblack.h" +#include #ifndef lint __unused static const char rcsid[] = "$Sudo$"; @@ -129,7 +130,7 @@ alias_add(name, type, members) a->seqno = 0; list2tq(&a->members, members); if (rbinsert(aliases, a)) { - efree(a); + alias_free(a); snprintf(errbuf, sizeof(errbuf), "Alias `%s' already defined", name); return(errbuf); } @@ -165,10 +166,17 @@ alias_free(v) { struct alias *a = (struct alias *)v; struct member *m; + struct sudo_command *c; void *next; + efree(a->name); for (m = a->members.first; m != NULL; m = next) { next = m->next; + if (m->type == COMMAND) { + c = (struct sudo_command *) m->name; + efree(c->cmnd); + efree(c->args); + } efree(m->name); efree(m); } diff --git a/gram.c b/gram.c index d167bd41a..afb5a7bdf 100644 --- a/gram.c +++ b/gram.c @@ -717,6 +717,7 @@ init_parser(path, quiet) struct userspec *us; struct privilege *priv; struct cmndspec *cs; + struct sudo_command *c; while ((us = tq_pop(&userspecs)) != NULL) { while ((m = tq_pop(&us->users)) != NULL) { @@ -759,6 +760,11 @@ init_parser(path, quiet) efree(m); } } + if (cs->cmnd->type == COMMAND) { + c = (struct sudo_command *) cs->cmnd->name; + efree(c->cmnd); + efree(c->args); + } efree(cs->cmnd->name); efree(cs->cmnd); efree(cs); @@ -773,6 +779,11 @@ init_parser(path, quiet) if (tq_last(&d->binding) != binding) { binding = tq_last(&d->binding); while ((m = tq_pop(&d->binding)) != NULL) { + if (m->type == COMMAND) { + c = (struct sudo_command *) m->name; + efree(c->cmnd); + efree(c->args); + } efree(m->name); efree(m); } @@ -793,7 +804,7 @@ init_parser(path, quiet) sudolineno = 1; verbose = !quiet; } -#line 745 "y.tab.c" +#line 756 "y.tab.c" /* allocate initial stack or double stack size, up to YYMAXDEPTH */ #if defined(__cplusplus) || defined(__STDC__) static int yygrowstack(void) @@ -1530,7 +1541,7 @@ case 92: yyval.member = new_member(yyvsp[0].string, WORD); } break; -#line 1482 "y.tab.c" +#line 1493 "y.tab.c" } yyssp -= yym; yystate = *yyssp; diff --git a/gram.y b/gram.y index c3b939d97..6290b43ad 100644 --- a/gram.y +++ b/gram.y @@ -686,6 +686,7 @@ init_parser(path, quiet) struct userspec *us; struct privilege *priv; struct cmndspec *cs; + struct sudo_command *c; while ((us = tq_pop(&userspecs)) != NULL) { while ((m = tq_pop(&us->users)) != NULL) { @@ -728,6 +729,11 @@ init_parser(path, quiet) efree(m); } } + if (cs->cmnd->type == COMMAND) { + c = (struct sudo_command *) cs->cmnd->name; + efree(c->cmnd); + efree(c->args); + } efree(cs->cmnd->name); efree(cs->cmnd); efree(cs); @@ -742,6 +748,11 @@ init_parser(path, quiet) if (tq_last(&d->binding) != binding) { binding = tq_last(&d->binding); while ((m = tq_pop(&d->binding)) != NULL) { + if (m->type == COMMAND) { + c = (struct sudo_command *) m->name; + efree(c->cmnd); + efree(c->args); + } efree(m->name); efree(m); } diff --git a/toke.c b/toke.c index 88d3ec9a6..35782e3d6 100644 --- a/toke.c +++ b/toke.c @@ -1852,8 +1852,6 @@ YY_RULE_SETUP int n; for (n = 0; isblank((unsigned char)yytext[n]); n++) continue; - if (!fill(yytext + n, yyleng - n)) - yyterminate(); switch (yytext[n]) { case 'H': LEXTRACE("HOSTALIAS "); @@ -1872,7 +1870,7 @@ YY_RULE_SETUP YY_BREAK case 19: YY_RULE_SETUP -#line 279 "toke.l" +#line 277 "toke.l" { /* cmnd does not require passwd for this user */ LEXTRACE("NOPASSWD "); @@ -1881,7 +1879,7 @@ YY_RULE_SETUP YY_BREAK case 20: YY_RULE_SETUP -#line 285 "toke.l" +#line 283 "toke.l" { /* cmnd requires passwd for this user */ LEXTRACE("PASSWD "); @@ -1890,7 +1888,7 @@ YY_RULE_SETUP YY_BREAK case 21: YY_RULE_SETUP -#line 291 "toke.l" +#line 289 "toke.l" { LEXTRACE("NOEXEC "); return(NOEXEC); @@ -1898,7 +1896,7 @@ YY_RULE_SETUP YY_BREAK case 22: YY_RULE_SETUP -#line 296 "toke.l" +#line 294 "toke.l" { LEXTRACE("EXEC "); return(EXEC); @@ -1906,7 +1904,7 @@ YY_RULE_SETUP YY_BREAK case 23: YY_RULE_SETUP -#line 301 "toke.l" +#line 299 "toke.l" { LEXTRACE("SETENV "); return(SETENV); @@ -1914,7 +1912,7 @@ YY_RULE_SETUP YY_BREAK case 24: YY_RULE_SETUP -#line 306 "toke.l" +#line 304 "toke.l" { LEXTRACE("NOSETENV "); return(NOSETENV); @@ -1922,7 +1920,7 @@ YY_RULE_SETUP YY_BREAK case 25: YY_RULE_SETUP -#line 311 "toke.l" +#line 309 "toke.l" { /* netgroup */ if (!fill(yytext, yyleng)) @@ -1933,7 +1931,7 @@ YY_RULE_SETUP YY_BREAK case 26: YY_RULE_SETUP -#line 319 "toke.l" +#line 317 "toke.l" { /* UN*X group */ if (!fill(yytext, yyleng)) @@ -1944,7 +1942,7 @@ YY_RULE_SETUP YY_BREAK case 27: YY_RULE_SETUP -#line 327 "toke.l" +#line 325 "toke.l" { if (!fill(yytext, yyleng)) yyterminate(); @@ -1954,7 +1952,7 @@ YY_RULE_SETUP YY_BREAK case 28: YY_RULE_SETUP -#line 334 "toke.l" +#line 332 "toke.l" { if (!fill(yytext, yyleng)) yyterminate(); @@ -1964,7 +1962,7 @@ YY_RULE_SETUP YY_BREAK case 29: YY_RULE_SETUP -#line 341 "toke.l" +#line 339 "toke.l" { if (!ipv6_valid(yytext)) { LEXTRACE("ERROR "); @@ -1978,7 +1976,7 @@ YY_RULE_SETUP YY_BREAK case 30: YY_RULE_SETUP -#line 352 "toke.l" +#line 350 "toke.l" { if (!ipv6_valid(yytext)) { LEXTRACE("ERROR "); @@ -1992,7 +1990,7 @@ YY_RULE_SETUP YY_BREAK case 31: YY_RULE_SETUP -#line 363 "toke.l" +#line 361 "toke.l" { if (strcmp(yytext, "ALL") == 0) { LEXTRACE("ALL "); @@ -2017,7 +2015,7 @@ YY_RULE_SETUP YY_BREAK case 32: YY_RULE_SETUP -#line 385 "toke.l" +#line 383 "toke.l" { /* no command args allowed for Defaults!/path */ if (!fill_cmnd(yytext, yyleng)) @@ -2028,7 +2026,7 @@ YY_RULE_SETUP YY_BREAK case 33: YY_RULE_SETUP -#line 393 "toke.l" +#line 391 "toke.l" { BEGIN GOTCMND; LEXTRACE("COMMAND "); @@ -2038,7 +2036,7 @@ YY_RULE_SETUP YY_BREAK case 34: YY_RULE_SETUP -#line 400 "toke.l" +#line 398 "toke.l" { /* directories can't have args... */ if (yytext[yyleng - 1] == '/') { @@ -2056,7 +2054,7 @@ YY_RULE_SETUP YY_BREAK case 35: YY_RULE_SETUP -#line 415 "toke.l" +#line 413 "toke.l" { /* a word */ if (!fill(yytext, yyleng)) @@ -2067,7 +2065,7 @@ YY_RULE_SETUP YY_BREAK case 36: YY_RULE_SETUP -#line 423 "toke.l" +#line 421 "toke.l" { LEXTRACE("( "); return ('('); @@ -2075,7 +2073,7 @@ YY_RULE_SETUP YY_BREAK case 37: YY_RULE_SETUP -#line 428 "toke.l" +#line 426 "toke.l" { LEXTRACE(") "); return(')'); @@ -2083,7 +2081,7 @@ YY_RULE_SETUP YY_BREAK case 38: YY_RULE_SETUP -#line 433 "toke.l" +#line 431 "toke.l" { LEXTRACE(", "); return(','); @@ -2091,7 +2089,7 @@ YY_RULE_SETUP YY_BREAK case 39: YY_RULE_SETUP -#line 438 "toke.l" +#line 436 "toke.l" { LEXTRACE("= "); return('='); @@ -2099,7 +2097,7 @@ YY_RULE_SETUP YY_BREAK case 40: YY_RULE_SETUP -#line 443 "toke.l" +#line 441 "toke.l" { LEXTRACE(": "); return(':'); @@ -2107,7 +2105,7 @@ YY_RULE_SETUP YY_BREAK case 41: YY_RULE_SETUP -#line 448 "toke.l" +#line 446 "toke.l" { if (yyleng % 2 == 1) return('!'); /* return '!' */ @@ -2115,7 +2113,7 @@ YY_RULE_SETUP YY_BREAK case 42: YY_RULE_SETUP -#line 453 "toke.l" +#line 451 "toke.l" { BEGIN INITIAL; ++sudolineno; @@ -2125,14 +2123,14 @@ YY_RULE_SETUP YY_BREAK case 43: YY_RULE_SETUP -#line 460 "toke.l" +#line 458 "toke.l" { /* throw away space/tabs */ sawspace = TRUE; /* but remember for fill_args */ } YY_BREAK case 44: YY_RULE_SETUP -#line 464 "toke.l" +#line 462 "toke.l" { sawspace = TRUE; /* remember for fill_args */ ++sudolineno; @@ -2141,7 +2139,7 @@ YY_RULE_SETUP YY_BREAK case 45: YY_RULE_SETUP -#line 470 "toke.l" +#line 468 "toke.l" { BEGIN INITIAL; ++sudolineno; @@ -2151,7 +2149,7 @@ YY_RULE_SETUP YY_BREAK case 46: YY_RULE_SETUP -#line 477 "toke.l" +#line 475 "toke.l" { LEXTRACE("ERROR "); return(ERROR); @@ -2163,7 +2161,7 @@ case YY_STATE_EOF(GOTCMND): case YY_STATE_EOF(STARTDEFS): case YY_STATE_EOF(INDEFS): case YY_STATE_EOF(INSTR): -#line 482 "toke.l" +#line 480 "toke.l" { if (YY_START != INITIAL) { BEGIN INITIAL; @@ -2176,10 +2174,10 @@ case YY_STATE_EOF(INSTR): YY_BREAK case 47: YY_RULE_SETUP -#line 492 "toke.l" +#line 490 "toke.l" ECHO; YY_BREAK -#line 2183 "lex.yy.c" +#line 2181 "lex.yy.c" case YY_END_OF_BUFFER: { @@ -3068,7 +3066,7 @@ int main() return 0; } #endif -#line 492 "toke.l" +#line 490 "toke.l" static int _fill(src, len, olen) diff --git a/toke.l b/toke.l index 5ec32da9b..9f924e98b 100644 --- a/toke.l +++ b/toke.l @@ -258,8 +258,6 @@ DEFVAR [a-z_]+ int n; for (n = 0; isblank((unsigned char)yytext[n]); n++) continue; - if (!fill(yytext + n, yyleng - n)) - yyterminate(); switch (yytext[n]) { case 'H': LEXTRACE("HOSTALIAS ");