Fix assorted memory leak/buffer reuse problems.
Not restricted to, but including: PR: kern/9631 Submitted by: Bill Fenner <fenner@parc.xerox.com>
This commit is contained in:
parent
6eb1682c86
commit
85f0ea7590
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: interp.c,v 1.13 1999/01/22 23:50:13 msmith Exp $
|
||||
* $Id: interp.c,v 1.14 1999/02/04 17:06:46 dcs Exp $
|
||||
*/
|
||||
/*
|
||||
* Simple commandline interpreter, toplevel and misc.
|
||||
@ -148,10 +148,23 @@ command_include(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
int res;
|
||||
char **argvbuf;
|
||||
|
||||
/*
|
||||
* Since argv is static, we need to save it here.
|
||||
*/
|
||||
argvbuf = (char**) calloc(argc, sizeof(char*));
|
||||
for (i = 0; i < argc; i++)
|
||||
argvbuf[i] = strdup(argv[i]);
|
||||
|
||||
res=CMD_OK;
|
||||
for (i = 1; (i < argc) && (res == CMD_OK); i++)
|
||||
res = include(argv[i]);
|
||||
res = include(argvbuf[i]);
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
free(argvbuf[i]);
|
||||
free(argvbuf);
|
||||
|
||||
return(res);
|
||||
}
|
||||
|
||||
@ -243,7 +256,7 @@ include(char *filename)
|
||||
#ifdef BOOT_FORTH
|
||||
res = bf_run(sp->text);
|
||||
if (res != VM_OUTOFTEXT) {
|
||||
sprintf(command_errbuf, "Error while including %s:\n%s", filename, sp->text);
|
||||
sprintf(command_errbuf, "Error while including %s, in the line:\n%s", filename, sp->text);
|
||||
res = CMD_ERROR;
|
||||
break;
|
||||
} else
|
||||
|
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: module.c,v 1.6 1998/10/09 23:12:34 peter Exp $
|
||||
* $Id: module.c,v 1.7 1999/01/11 06:41:31 msmith Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -256,6 +256,7 @@ mod_loadobj(char *type, char *name)
|
||||
break;
|
||||
if (got < 0) { /* error */
|
||||
sprintf(command_errbuf, "error reading '%s': %s", name, strerror(errno));
|
||||
free(name);
|
||||
return(CMD_ERROR);
|
||||
}
|
||||
laddr += got;
|
||||
@ -263,7 +264,7 @@ mod_loadobj(char *type, char *name)
|
||||
|
||||
/* Looks OK so far; create & populate control structure */
|
||||
mp = malloc(sizeof(struct loaded_module));
|
||||
mp->m_name = strdup(name);
|
||||
mp->m_name = name;
|
||||
mp->m_type = strdup(type);
|
||||
mp->m_args = NULL;
|
||||
mp->m_metadata = NULL;
|
||||
@ -442,9 +443,12 @@ mod_searchfile(char *name)
|
||||
struct stat sb;
|
||||
|
||||
/* Don't look for nothing */
|
||||
if ((name == NULL) || (*name == 0))
|
||||
if (name == NULL)
|
||||
return(name);
|
||||
|
||||
if (*name == 0)
|
||||
return(strdup(name));
|
||||
|
||||
/*
|
||||
* See if there's a device on the front, or a directory name.
|
||||
*/
|
||||
@ -452,7 +456,7 @@ mod_searchfile(char *name)
|
||||
if ((cp != name) || (strchr(name, '/') != NULL)) {
|
||||
/* Qualified, so just see if it exists */
|
||||
if (stat(name, &sb) == 0)
|
||||
return(name);
|
||||
return(strdup(name));
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user