Add efree() for consistency with emalloc() et al. Allows us to rely

on C89 behavior (free(NULL) is valid) even on K&R.
This commit is contained in:
Todd C. Miller
2005-03-29 14:29:47 +00:00
parent 9efe91fa1e
commit 304dc46d7f
19 changed files with 107 additions and 125 deletions

View File

@@ -116,7 +116,7 @@ alias_add(name, type, members)
a->type = type; a->type = type;
a->first_member = members; a->first_member = members;
if (rbinsert(aliases, a)) { if (rbinsert(aliases, a)) {
free(a); efree(a);
snprintf(errbuf, sizeof(errbuf), "Alias `%s' already defined", name); snprintf(errbuf, sizeof(errbuf), "Alias `%s' already defined", name);
return(errbuf); return(errbuf);
} }
@@ -156,11 +156,10 @@ alias_free(v)
for (m = a->first_member; m != NULL; m = next) { for (m = a->first_member; m != NULL; m = next) {
next = m->next; next = m->next;
if (m->name != NULL) efree(m->name);
free(m->name); efree(m);
free(m);
} }
free(a); efree(a);
} }
/* /*

11
alloc.c
View File

@@ -211,3 +211,14 @@ evasprintf(ret, format, args)
errorx(1, "unable to allocate memory"); errorx(1, "unable to allocate memory");
return(len); return(len);
} }
/*
* Wrapper for free(3) so we can depend on C89 semantics.
*/
void
efree(ptr)
VOID *ptr;
{
if (ptr != NULL)
free(ptr);
}

10
check.c
View File

@@ -100,9 +100,8 @@ check_user(override)
} }
if (status != TS_ERROR) if (status != TS_ERROR)
update_timestamp(timestampdir, timestampfile); update_timestamp(timestampdir, timestampfile);
free(timestampdir); efree(timestampdir);
if (timestampfile) efree(timestampfile);
free(timestampfile);
} }
/* /*
@@ -551,7 +550,6 @@ remove_timestamp(remove)
} }
} }
free(timestampdir); efree(timestampdir);
if (timestampfile) efree(timestampfile);
free(timestampfile);
} }

View File

@@ -362,10 +362,8 @@ init_defaults()
for (def = sudo_defs_table; def->name; def++) { for (def = sudo_defs_table; def->name; def++) {
switch (def->type & T_MASK) { switch (def->type & T_MASK) {
case T_STR: case T_STR:
if (def->sd_un.str) { efree(def->sd_un.str);
free(def->sd_un.str);
def->sd_un.str = NULL; def->sd_un.str = NULL;
}
break; break;
case T_LIST: case T_LIST:
list_op(NULL, 0, def, freeall); list_op(NULL, 0, def, freeall);
@@ -621,8 +619,7 @@ store_str(val, def, op)
int op; int op;
{ {
if (def->sd_un.str) efree(def->sd_un.str);
free(def->sd_un.str);
if (op == FALSE) if (op == FALSE)
def->sd_un.str = NULL; def->sd_un.str = NULL;
else else
@@ -771,8 +768,8 @@ list_op(val, len, def, op)
for (cur = def->sd_un.list; cur; ) { for (cur = def->sd_un.list; cur; ) {
tmp = cur; tmp = cur;
cur = tmp->next; cur = tmp->next;
free(tmp->value); efree(tmp->value);
free(tmp); efree(tmp);
} }
def->sd_un.list = NULL; def->sd_un.list = NULL;
return; return;
@@ -789,8 +786,8 @@ list_op(val, len, def, op)
prev->next = cur->next; prev->next = cur->next;
else else
def->sd_un.list = cur->next; def->sd_un.list = cur->next;
free(cur->value); efree(cur->value);
free(cur); efree(cur);
break; break;
} }
} }

View File

@@ -120,7 +120,7 @@ find_path(infile, outfile, sbp, path)
path = n + 1; path = n + 1;
} while (n); } while (n);
free(origpath); efree(origpath);
/* /*
* Check current dir if dot was in the PATH * Check current dir if dot was in the PATH

45
gram.c
View File

@@ -664,35 +664,31 @@ init_parser(path, quiet)
for (us = userspecs; us != NULL; us = next) { for (us = userspecs; us != NULL; us = next) {
for (m = us->user; m != NULL; m = next) { for (m = us->user; m != NULL; m = next) {
next = m->next; next = m->next;
if (m->name != NULL) efree(m->name);
free(m->name); efree(m);
free(m);
} }
for (priv = us->privileges; priv != NULL; priv = next) { for (priv = us->privileges; priv != NULL; priv = next) {
for (m = priv->hostlist; m != NULL; m = next) { for (m = priv->hostlist; m != NULL; m = next) {
next = m->next; next = m->next;
if (m->name != NULL) efree(m->name);
free(m->name); efree(m);
free(m);
} }
for (cs = priv->cmndlist; cs != NULL; cs = next) { for (cs = priv->cmndlist; cs != NULL; cs = next) {
for (m = cs->runaslist; m != NULL; m = next) { for (m = cs->runaslist; m != NULL; m = next) {
next = m->next; next = m->next;
if (m->name != NULL) efree(m->name);
free(m->name); efree(m);
free(m);
} }
if (cs->cmnd->name != NULL) efree(cs->cmnd->name);
free(cs->cmnd->name); efree(cs->cmnd);
free(cs->cmnd);
next = cs->next; next = cs->next;
free(cs); efree(cs);
} }
next = priv->next; next = priv->next;
free(priv); efree(priv);
} }
next = us->next; next = us->next;
free(us); efree(us);
} }
userspecs = NULL; userspecs = NULL;
@@ -701,24 +697,21 @@ init_parser(path, quiet)
if (d->binding != lastbinding) { if (d->binding != lastbinding) {
for (m = d->binding; m != NULL; m = next) { for (m = d->binding; m != NULL; m = next) {
next = m->next; next = m->next;
if (m->name != NULL) efree(m->name);
free(m->name); efree(m);
free(m);
} }
lastbinding = d->binding; lastbinding = d->binding;
} }
next = d->next; next = d->next;
free(d->var); efree(d->var);
if (d->val != NULL) efree(d->val);
free(d->val); efree(d);
free(d);
} }
defaults = NULL; defaults = NULL;
init_aliases(); init_aliases();
if (sudoers != NULL) efree(sudoers);
free(sudoers);
sudoers = estrdup(path); sudoers = estrdup(path);
parse_error = FALSE; parse_error = FALSE;
@@ -726,7 +719,7 @@ init_parser(path, quiet)
sudolineno = 1; sudolineno = 1;
verbose = !quiet; verbose = !quiet;
} }
#line 678 "gram.c" #line 671 "gram.c"
/* allocate initial stack or double stack size, up to YYMAXDEPTH */ /* allocate initial stack or double stack size, up to YYMAXDEPTH */
#if defined(__cplusplus) || defined(__STDC__) #if defined(__cplusplus) || defined(__STDC__)
static int yygrowstack(void) static int yygrowstack(void)
@@ -1371,7 +1364,7 @@ case 84:
NEW_MEMBER(yyval.member, yyvsp[0].string, WORD); NEW_MEMBER(yyval.member, yyvsp[0].string, WORD);
} }
break; break;
#line 1323 "gram.c" #line 1316 "gram.c"
} }
yyssp -= yym; yyssp -= yym;
yystate = *yyssp; yystate = *yyssp;

41
gram.y
View File

@@ -562,35 +562,31 @@ init_parser(path, quiet)
for (us = userspecs; us != NULL; us = next) { for (us = userspecs; us != NULL; us = next) {
for (m = us->user; m != NULL; m = next) { for (m = us->user; m != NULL; m = next) {
next = m->next; next = m->next;
if (m->name != NULL) efree(m->name);
free(m->name); efree(m);
free(m);
} }
for (priv = us->privileges; priv != NULL; priv = next) { for (priv = us->privileges; priv != NULL; priv = next) {
for (m = priv->hostlist; m != NULL; m = next) { for (m = priv->hostlist; m != NULL; m = next) {
next = m->next; next = m->next;
if (m->name != NULL) efree(m->name);
free(m->name); efree(m);
free(m);
} }
for (cs = priv->cmndlist; cs != NULL; cs = next) { for (cs = priv->cmndlist; cs != NULL; cs = next) {
for (m = cs->runaslist; m != NULL; m = next) { for (m = cs->runaslist; m != NULL; m = next) {
next = m->next; next = m->next;
if (m->name != NULL) efree(m->name);
free(m->name); efree(m);
free(m);
} }
if (cs->cmnd->name != NULL) efree(cs->cmnd->name);
free(cs->cmnd->name); efree(cs->cmnd);
free(cs->cmnd);
next = cs->next; next = cs->next;
free(cs); efree(cs);
} }
next = priv->next; next = priv->next;
free(priv); efree(priv);
} }
next = us->next; next = us->next;
free(us); efree(us);
} }
userspecs = NULL; userspecs = NULL;
@@ -599,24 +595,21 @@ init_parser(path, quiet)
if (d->binding != lastbinding) { if (d->binding != lastbinding) {
for (m = d->binding; m != NULL; m = next) { for (m = d->binding; m != NULL; m = next) {
next = m->next; next = m->next;
if (m->name != NULL) efree(m->name);
free(m->name); efree(m);
free(m);
} }
lastbinding = d->binding; lastbinding = d->binding;
} }
next = d->next; next = d->next;
free(d->var); efree(d->var);
if (d->val != NULL) efree(d->val);
free(d->val); efree(d);
free(d);
} }
defaults = NULL; defaults = NULL;
init_aliases(); init_aliases();
if (sudoers != NULL) efree(sudoers);
free(sudoers);
sudoers = estrdup(path); sudoers = estrdup(path);
parse_error = FALSE; parse_error = FALSE;

View File

@@ -146,7 +146,7 @@ load_interfaces()
#ifdef HAVE_FREEIFADDRS #ifdef HAVE_FREEIFADDRS
freeifaddrs(ifaddrs); freeifaddrs(ifaddrs);
#else #else
free(ifaddrs); efree(ifaddrs);
#endif #endif
} }
@@ -189,7 +189,7 @@ load_interfaces()
#else #else
if (ioctl(sock, SIOCGIFCONF, (caddr_t) ifconf) < 0) { if (ioctl(sock, SIOCGIFCONF, (caddr_t) ifconf) < 0) {
#endif /* _ISC */ #endif /* _ISC */
free(ifconf_buf); efree(ifconf_buf);
(void) close(sock); (void) close(sock);
return; return;
} }
@@ -279,9 +279,9 @@ load_interfaces()
interfaces = (struct interface *) erealloc3(interfaces, interfaces = (struct interface *) erealloc3(interfaces,
num_interfaces, sizeof(struct interface)); num_interfaces, sizeof(struct interface));
else else
free(interfaces); efree(interfaces);
} }
free(ifconf_buf); efree(ifconf_buf);
(void) close(sock); (void) close(sock);
} }

12
ldap.c
View File

@@ -260,8 +260,7 @@ sudo_ldap_check_command(ld, entry)
/* Match against ALL ? */ /* Match against ALL ? */
if (!strcasecmp(*p, "ALL")) { if (!strcasecmp(*p, "ALL")) {
ret = TRUE; ret = TRUE;
if (safe_cmnd) efree(safe_cmnd);
free(safe_cmnd);
safe_cmnd = estrdup(user_cmnd); safe_cmnd = estrdup(user_cmnd);
if (ldap_conf.debug > 1) if (ldap_conf.debug > 1)
printf(" MATCH!\n"); printf(" MATCH!\n");
@@ -295,7 +294,7 @@ sudo_ldap_check_command(ld, entry)
printf(" not\n"); printf(" not\n");
} }
free(allowed_cmnd); /* cleanup */ efree(allowed_cmnd); /* cleanup */
} }
if (v) if (v)
@@ -348,7 +347,7 @@ sudo_ldap_parse_options(ld, entry)
/* case var Boolean True */ /* case var Boolean True */
set_default(var, NULL, TRUE); set_default(var, NULL, TRUE);
} }
free(var); efree(var);
} }
if (v) if (v)
@@ -524,7 +523,7 @@ sudo_ldap_read_config()
/* The following macros make the code much more readable */ /* The following macros make the code much more readable */
#define MATCH_S(x,y) if (!strcasecmp(keyword,x)) \ #define MATCH_S(x,y) if (!strcasecmp(keyword,x)) \
{ if (y) free(y); y=estrdup(value); } { efree(y); y=estrdup(value); }
#define MATCH_I(x,y) if (!strcasecmp(keyword,x)) { y=atoi(value); } #define MATCH_I(x,y) if (!strcasecmp(keyword,x)) { y=atoi(value); }
#define MATCH_B(x,y) if (!strcasecmp(keyword,x)) { y=_atobool(value); } #define MATCH_B(x,y) if (!strcasecmp(keyword,x)) { y=_atobool(value); }
@@ -905,8 +904,7 @@ sudo_ldap_check(v, pwflag)
if (ldap_conf.debug) if (ldap_conf.debug)
printf("nothing found for '%s'\n", filt); printf("nothing found for '%s'\n", filt);
} }
if (filt) efree(filt);
free(filt);
/* parse each entry returned from this most recent search */ /* parse each entry returned from this most recent search */
entry = rc ? NULL : ldap_first_entry(ld, result); entry = rc ? NULL : ldap_first_entry(ld, result);

View File

@@ -189,12 +189,12 @@ do_logfile(msg)
easprintf(&full_line, "Can't open log file: %s: %s", easprintf(&full_line, "Can't open log file: %s: %s",
def_logfile, strerror(errno)); def_logfile, strerror(errno));
send_mail(full_line); send_mail(full_line);
free(full_line); efree(full_line);
} else if (!lock_file(fileno(fp), SUDO_LOCK)) { } else if (!lock_file(fileno(fp), SUDO_LOCK)) {
easprintf(&full_line, "Can't lock log file: %s: %s", easprintf(&full_line, "Can't lock log file: %s: %s",
def_logfile, strerror(errno)); def_logfile, strerror(errno));
send_mail(full_line); send_mail(full_line);
free(full_line); efree(full_line);
} else { } else {
if (def_loglinelen == 0) { if (def_loglinelen == 0) {
/* Don't pretty-print long log file lines (hard to grep) */ /* Don't pretty-print long log file lines (hard to grep) */
@@ -259,7 +259,7 @@ do_logfile(msg)
beg = NULL; /* exit condition */ beg = NULL; /* exit condition */
} }
} }
free(full_line); efree(full_line);
} }
(void) fflush(fp); (void) fflush(fp);
(void) lock_file(fileno(fp), SUDO_UNLOCK); (void) lock_file(fileno(fp), SUDO_UNLOCK);
@@ -330,7 +330,7 @@ log_auth(status, inform_user)
if (def_logfile) if (def_logfile)
do_logfile(logline); do_logfile(logline);
free(logline); efree(logline);
} }
void void
@@ -410,9 +410,9 @@ log_error(flags, fmt, va_alist)
if (def_logfile) if (def_logfile)
do_logfile(logline); do_logfile(logline);
free(message); efree(message);
if (logline != message) if (logline != message)
free(logline); efree(logline);
if (!ISSET(flags, NO_EXIT)) if (!ISSET(flags, NO_EXIT))
exit(1); exit(1);

17
match.c
View File

@@ -293,8 +293,7 @@ command_matches(sudoers_cmnd, sudoers_args)
(!user_args && sudoers_args && !strcmp("\"\"", sudoers_args)) || (!user_args && sudoers_args && !strcmp("\"\"", sudoers_args)) ||
(sudoers_args && (sudoers_args &&
fnmatch(sudoers_args, user_args ? user_args : "", 0) == 0)) { fnmatch(sudoers_args, user_args ? user_args : "", 0) == 0)) {
if (safe_cmnd) efree(safe_cmnd);
free(safe_cmnd);
safe_cmnd = estrdup(sudoers_cmnd); safe_cmnd = estrdup(sudoers_cmnd);
return(TRUE); return(TRUE);
} else } else
@@ -331,8 +330,7 @@ command_matches(sudoers_cmnd, sudoers_args)
if (user_stat == NULL || if (user_stat == NULL ||
(user_stat->st_dev == sudoers_stat.st_dev && (user_stat->st_dev == sudoers_stat.st_dev &&
user_stat->st_ino == sudoers_stat.st_ino)) { user_stat->st_ino == sudoers_stat.st_ino)) {
if (safe_cmnd) efree(safe_cmnd);
free(safe_cmnd);
safe_cmnd = estrdup(*ap); safe_cmnd = estrdup(*ap);
break; break;
} }
@@ -345,8 +343,7 @@ command_matches(sudoers_cmnd, sudoers_args)
(!user_args && sudoers_args && !strcmp("\"\"", sudoers_args)) || (!user_args && sudoers_args && !strcmp("\"\"", sudoers_args)) ||
(sudoers_args && (sudoers_args &&
fnmatch(sudoers_args, user_args ? user_args : "", 0) == 0)) { fnmatch(sudoers_args, user_args ? user_args : "", 0) == 0)) {
if (safe_cmnd) efree(safe_cmnd);
free(safe_cmnd);
safe_cmnd = estrdup(user_cmnd); safe_cmnd = estrdup(user_cmnd);
return(TRUE); return(TRUE);
} else } else
@@ -382,8 +379,7 @@ command_matches(sudoers_cmnd, sudoers_args)
(!user_args && sudoers_args && !strcmp("\"\"", sudoers_args)) || (!user_args && sudoers_args && !strcmp("\"\"", sudoers_args)) ||
(sudoers_args && (sudoers_args &&
fnmatch(sudoers_args, user_args ? user_args : "", 0) == 0)) { fnmatch(sudoers_args, user_args ? user_args : "", 0) == 0)) {
if (safe_cmnd) efree(safe_cmnd);
free(safe_cmnd);
safe_cmnd = estrdup(sudoers_cmnd); safe_cmnd = estrdup(sudoers_cmnd);
return(TRUE); return(TRUE);
} else } else
@@ -411,8 +407,7 @@ command_matches(sudoers_cmnd, sudoers_args)
continue; continue;
if (user_stat->st_dev == sudoers_stat.st_dev && if (user_stat->st_dev == sudoers_stat.st_dev &&
user_stat->st_ino == sudoers_stat.st_ino) { user_stat->st_ino == sudoers_stat.st_ino) {
if (safe_cmnd) efree(safe_cmnd);
free(safe_cmnd);
safe_cmnd = estrdup(buf); safe_cmnd = estrdup(buf);
break; break;
} }
@@ -581,7 +576,7 @@ netgr_matches(netgr, lhost, shost, user)
if (domain == (char *) -1) { if (domain == (char *) -1) {
domain = (char *) emalloc(MAXHOSTNAMELEN); domain = (char *) emalloc(MAXHOSTNAMELEN);
if (getdomainname(domain, MAXHOSTNAMELEN) == -1 || *domain == '\0') { if (getdomainname(domain, MAXHOSTNAMELEN) == -1 || *domain == '\0') {
free(domain); efree(domain);
domain = NULL; domain = NULL;
} }
} }

View File

@@ -363,7 +363,7 @@ rm_child(pid)
prev->next = cur->next; prev->next = cur->next;
else else
children.first = cur->next; children.first = cur->next;
free(cur); efree(cur);
break; break;
} }
prev = cur; prev = cur;

View File

@@ -290,11 +290,11 @@ sudo_fakepwuid(uid)
/* Store by uid and by name, overwriting cached version. */ /* Store by uid and by name, overwriting cached version. */
if ((node = rbinsert(pwcache_byuid, pw)) != NULL) { if ((node = rbinsert(pwcache_byuid, pw)) != NULL) {
free(node->data); efree(node->data);
node->data = (VOID *) pw; node->data = (VOID *) pw;
} }
if ((node = rbinsert(pwcache_byname, pw)) != NULL) { if ((node = rbinsert(pwcache_byname, pw)) != NULL) {
free(node->data); efree(node->data);
node->data = (VOID *) pw; node->data = (VOID *) pw;
} }
return(pw); return(pw);
@@ -320,11 +320,11 @@ sudo_fakepwnam(user)
/* Store by uid and by name, overwriting cached version. */ /* Store by uid and by name, overwriting cached version. */
if ((node = rbinsert(pwcache_byuid, pw)) != NULL) { if ((node = rbinsert(pwcache_byuid, pw)) != NULL) {
free(node->data); efree(node->data);
node->data = (VOID *) pw; node->data = (VOID *) pw;
} }
if ((node = rbinsert(pwcache_byname, pw)) != NULL) { if ((node = rbinsert(pwcache_byname, pw)) != NULL) {
free(node->data); efree(node->data);
node->data = (VOID *) pw; node->data = (VOID *) pw;
} }
return(pw); return(pw);
@@ -362,9 +362,9 @@ pw_free(v)
if (pw->pw_passwd != NULL) { if (pw->pw_passwd != NULL) {
zero_bytes(pw->pw_passwd, strlen(pw->pw_passwd)); zero_bytes(pw->pw_passwd, strlen(pw->pw_passwd));
free(pw->pw_passwd); efree(pw->pw_passwd);
} }
free(pw); efree(pw);
} }
/* /*

View File

@@ -326,7 +326,7 @@ _rbdestroy(tree, node, destroy)
_rbdestroy(tree, node->right, destroy); _rbdestroy(tree, node->right, destroy);
if (destroy != NULL) if (destroy != NULL)
destroy(node->data); destroy(node->data);
free(node); efree(node);
} }
} }
@@ -340,7 +340,7 @@ rbdestroy(tree, destroy)
void (*destroy)__P((VOID *)); void (*destroy)__P((VOID *));
{ {
_rbdestroy(tree, rbfirst(tree), destroy); _rbdestroy(tree, rbfirst(tree), destroy);
free(tree); efree(tree);
} }
/* /*
@@ -379,7 +379,7 @@ rbdelete(tree, victim)
else else
victim->parent->right = succ; victim->parent->right = succ;
data = victim->data; data = victim->data;
free(victim); efree(victim);
} else { } else {
pred = victim->left == rbnil(tree) ? victim->right : victim->left; pred = victim->left == rbnil(tree) ? victim->right : victim->left;
if (victim->parent == rbroot(tree)) { if (victim->parent == rbroot(tree)) {
@@ -394,7 +394,7 @@ rbdelete(tree, victim)
if (victim->color == black) if (victim->color == black)
rbrepair(tree, pred); rbrepair(tree, pred);
data = victim->data; data = victim->data;
free(victim); efree(victim);
} }
return(data); return(data);
} }

4
sudo.c
View File

@@ -1091,8 +1091,8 @@ set_fqdn()
"unable to lookup %s via gethostbyname()", user_host); "unable to lookup %s via gethostbyname()", user_host);
} else { } else {
if (user_shost != user_host) if (user_shost != user_host)
free(user_shost); efree(user_shost);
free(user_host); efree(user_host);
user_host = estrdup(hp->h_name); user_host = estrdup(hp->h_name);
} }
if ((p = strchr(user_host, '.'))) { if ((p = strchr(user_host, '.'))) {

1
sudo.h
View File

@@ -237,6 +237,7 @@ int easprintf __P((char **, const char *, ...))
__printflike(2, 3); __printflike(2, 3);
int evasprintf __P((char **, const char *, va_list)) int evasprintf __P((char **, const char *, va_list))
__printflike(2, 0); __printflike(2, 0);
void efree __P((VOID *));
void dump_defaults __P((void)); void dump_defaults __P((void));
void dump_auth_methods __P((void)); void dump_auth_methods __P((void));
void init_envtables __P((void)); void init_envtables __P((void));

5
toke.c
View File

@@ -2756,8 +2756,7 @@ fill_args(s, len, addspace)
(char *) realloc(yylval.command.args, arg_size) : (char *) realloc(yylval.command.args, arg_size) :
(char *) malloc(arg_size); (char *) malloc(arg_size);
if (p == NULL) { if (p == NULL) {
if (yylval.command.args != NULL) efree(yylval.command.args);
free(yylval.command.args);
yyerror("unable to allocate memory"); yyerror("unable to allocate memory");
return(FALSE); return(FALSE);
} else } else
@@ -2833,7 +2832,7 @@ switch_buffer(path)
fclose(YY_CURRENT_BUFFER->yy_input_file); fclose(YY_CURRENT_BUFFER->yy_input_file);
yy_delete_buffer(YY_CURRENT_BUFFER); yy_delete_buffer(YY_CURRENT_BUFFER);
yy_switch_to_buffer(state[depth].bs); yy_switch_to_buffer(state[depth].bs);
free(sudoers); efree(sudoers);
sudoers = state[depth].path; sudoers = state[depth].path;
sudolineno = state[depth].lineno; sudolineno = state[depth].lineno;
keepopen = FALSE; keepopen = FALSE;

5
toke.l
View File

@@ -508,8 +508,7 @@ fill_args(s, len, addspace)
(char *) realloc(yylval.command.args, arg_size) : (char *) realloc(yylval.command.args, arg_size) :
(char *) malloc(arg_size); (char *) malloc(arg_size);
if (p == NULL) { if (p == NULL) {
if (yylval.command.args != NULL) efree(yylval.command.args);
free(yylval.command.args);
yyerror("unable to allocate memory"); yyerror("unable to allocate memory");
return(FALSE); return(FALSE);
} else } else
@@ -585,7 +584,7 @@ switch_buffer(path)
fclose(YY_CURRENT_BUFFER->yy_input_file); fclose(YY_CURRENT_BUFFER->yy_input_file);
yy_delete_buffer(YY_CURRENT_BUFFER); yy_delete_buffer(YY_CURRENT_BUFFER);
yy_switch_to_buffer(state[depth].bs); yy_switch_to_buffer(state[depth].bs);
free(sudoers); efree(sudoers);
sudoers = state[depth].path; sudoers = state[depth].path;
sudolineno = state[depth].lineno; sudolineno = state[depth].lineno;
keepopen = FALSE; keepopen = FALSE;

View File

@@ -489,7 +489,7 @@ install_sudoers(sp)
* mv(1) in case sp->tpath and sp->path are on different file systems. * mv(1) in case sp->tpath and sp->path are on different file systems.
*/ */
if (rename(sp->tpath, sp->path) == 0) { if (rename(sp->tpath, sp->path) == 0) {
free(sp->tpath); efree(sp->tpath);
sp->tpath = NULL; sp->tpath = NULL;
} else { } else {
if (errno == EXDEV) { if (errno == EXDEV) {
@@ -511,11 +511,11 @@ install_sudoers(sp)
warningx("command failed: '%s %s %s', %s unchanged", warningx("command failed: '%s %s %s', %s unchanged",
_PATH_MV, sp->tpath, sp->path, sp->path); _PATH_MV, sp->tpath, sp->path, sp->path);
(void) unlink(sp->tpath); (void) unlink(sp->tpath);
free(sp->tpath); efree(sp->tpath);
sp->tpath = NULL; sp->tpath = NULL;
return(FALSE); return(FALSE);
} }
free(sp->tpath); efree(sp->tpath);
sp->tpath = NULL; sp->tpath = NULL;
} else { } else {
warning("error renaming %s, %s unchanged", sp->tpath, sp->path); warning("error renaming %s, %s unchanged", sp->tpath, sp->path);
@@ -716,7 +716,7 @@ open_sudoers(path, keepopen)
entry->tpath = NULL; entry->tpath = NULL;
if (entry->fd == -1) { if (entry->fd == -1) {
warning("%s", entry->path); warning("%s", entry->path);
free(entry); efree(entry);
return(NULL); return(NULL);
} }
if (!lock_file(entry->fd, SUDO_TLOCK)) if (!lock_file(entry->fd, SUDO_TLOCK))
@@ -828,8 +828,7 @@ get_editor(args)
* find one that exists, is regular, and is executable. * find one that exists, is regular, and is executable.
*/ */
if (Editor == NULL || *Editor == '\0') { if (Editor == NULL || *Editor == '\0') {
if (EditorPath != NULL) efree(EditorPath);
free(EditorPath);
EditorPath = estrdup(def_editor); EditorPath = estrdup(def_editor);
Editor = strtok(EditorPath, ":"); Editor = strtok(EditorPath, ":");
do { do {