Coverity CID 2341, 2342: Plug memory leak.

This commit is contained in:
christos 2006-03-18 09:46:35 +00:00
parent 969e2244d4
commit 22983123c5
3 changed files with 28 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: defs.h,v 1.16 2003/08/07 11:15:35 agc Exp $ */
/* $NetBSD: defs.h,v 1.17 2006/03/18 09:46:35 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@ -173,8 +173,10 @@ struct namelist *
void lostconn(int);
struct namelist *
makenl(char *);
void freenl(struct namelist *);
struct subcmd *
makesubcmd(int);
void freesubcmd(struct subcmd *);
void prnames(struct namelist *);
void server(void);
void yyerror(char *);

View File

@ -1,5 +1,5 @@
%{
/* $NetBSD: gram.y,v 1.11 2003/10/21 02:23:13 fvdl Exp $ */
/* $NetBSD: gram.y,v 1.12 2006/03/18 09:46:35 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@ -35,7 +35,7 @@
#if 0
static char sccsid[] = "@(#)gram.y 8.1 (Berkeley) 6/9/93";
#else
__RCSID("$NetBSD: gram.y,v 1.11 2003/10/21 02:23:13 fvdl Exp $");
__RCSID("$NetBSD: gram.y,v 1.12 2006/03/18 09:46:35 christos Exp $");
#endif
#endif /* not lint */
@ -480,6 +480,24 @@ makenl(char *name)
return(nl);
}
void
freenl(struct namelist *nl)
{
if (nl == NULL)
return;
freenl(nl->n_next);
free(nl);
}
void
freesubcmd(struct subcmd *cmd)
{
if (cmd == NULL)
return;
freesubcmd(cmd->sc_next);
free(cmd);
}
/*
* Make a sub command for lists of variables, commands, etc.
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.17 2004/07/13 12:06:35 wiz Exp $ */
/* $NetBSD: main.c,v 1.18 2006/03/18 09:46:35 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/9/93";
#else
__RCSID("$NetBSD: main.c,v 1.17 2004/07/13 12:06:35 wiz Exp $");
__RCSID("$NetBSD: main.c,v 1.18 2006/03/18 09:46:35 christos Exp $");
#endif
#endif /* not lint */
@ -299,6 +299,9 @@ docmdargs(int nargs, char **args)
}
insert(NULL, files, hosts, cmds);
docmds(NULL, 0, NULL);
freenl(files);
freenl(hosts);
freesubcmd(cmds);
}
/*