summaryrefslogtreecommitdiffstats
path: root/sys/boot
diff options
context:
space:
mode:
authordcs <dcs@FreeBSD.org>1999-02-22 13:12:37 +0000
committerdcs <dcs@FreeBSD.org>1999-02-22 13:12:37 +0000
commit3b2e9c970d1b3c4670c145d0363db0fabc8ee122 (patch)
tree332b8d8aa02a493f27ddc9da58ee8b7fc486242d /sys/boot
parent62572be175c190ab32f7db9990d3169dd1883b83 (diff)
downloadFreeBSD-src-3b2e9c970d1b3c4670c145d0363db0fabc8ee122.zip
FreeBSD-src-3b2e9c970d1b3c4670c145d0363db0fabc8ee122.tar.gz
Fix assorted memory leak/buffer reuse problems.
Not restricted to, but including: PR: kern/9631 Submitted by: Bill Fenner <fenner@parc.xerox.com>
Diffstat (limited to 'sys/boot')
-rw-r--r--sys/boot/common/interp.c19
-rw-r--r--sys/boot/common/module.c12
2 files changed, 24 insertions, 7 deletions
diff --git a/sys/boot/common/interp.c b/sys/boot/common/interp.c
index 276548c..cc7f6ff 100644
--- a/sys/boot/common/interp.c
+++ b/sys/boot/common/interp.c
@@ -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
diff --git a/sys/boot/common/module.c b/sys/boot/common/module.c
index 141a8ed..bacdf7a 100644
--- a/sys/boot/common/module.c
+++ b/sys/boot/common/module.c
@@ -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);
}
OpenPOWER on IntegriCloud