From 304195a1776cf0370224c99f3635cc9a5a7f24c6 Mon Sep 17 00:00:00 2001 From: dcs Date: Mon, 8 Mar 1999 10:32:39 +0000 Subject: Fix a number of memory leaks and other memory-related disorders. Also, unbreak the breakage introduced at the last revision of module.c. This changes the semantics of mod_searchfile() (and mod_searchmodule()) to make the caller's responsibility freeing the buffer returned. This is different from other functions in loader's code, and was done as a fix for kern/9631. If someone wants to revert this to the original behavior, don't forget to fix kern/9631 in another way. This should also fix bin/10462, which was introduced as a result of the first try at kern/9631 (module.c last revision). PR: bin/10462 Submitted by: Takanori Saneto --- sys/boot/common/module.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'sys/boot/common/module.c') diff --git a/sys/boot/common/module.c b/sys/boot/common/module.c index bacdf7a..0141659 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.7 1999/01/11 06:41:31 msmith Exp $ + * $Id: module.c,v 1.8 1999/02/22 13:12:37 dcs Exp $ */ /* @@ -245,6 +245,7 @@ mod_loadobj(char *type, char *name) if ((fd = open(name, O_RDONLY)) < 0) { sprintf(command_errbuf, "can't open '%s': %s", name, strerror(errno)); + free(name); return(CMD_ERROR); } @@ -309,6 +310,7 @@ mod_loadmodule(char *name, int argc, char *argv[]) /* Fatal error */ sprintf(command_errbuf, "can't load module '%s': %s", name, strerror(err)); + free(name); return(NULL); } else { @@ -329,6 +331,7 @@ mod_loadmodule(char *name, int argc, char *argv[]) } if (err == EFTYPE) sprintf(command_errbuf, "don't know how to load module '%s'", name); + free(name); return(mp); } @@ -437,7 +440,7 @@ mod_findmetadata(struct loaded_module *mp, int type) static char * mod_searchfile(char *name) { - static char *result = NULL; + char *result; char *path, *sp; const char *cp; struct stat sb; @@ -470,8 +473,7 @@ mod_searchfile(char *name) /* * Traverse the path, splitting off ';'-delimited components. */ - if (result != NULL) - free(result); + result = NULL; while((cp = strsep(&path, ";")) != NULL) { result = malloc(strlen(cp) + strlen(name) + 5); strcpy(result, cp); -- cgit v1.1