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 <sanewo@ba2.so-net.ne.jp>
This commit is contained in:
parent
da3a3026b9
commit
08c9325cb2
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: commands.c,v 1.9 1999/01/11 06:41:31 msmith Exp $
|
||||
* $Id: commands.c,v 1.10 1999/02/01 06:08:20 jkh Exp $
|
||||
*/
|
||||
|
||||
#include <stand.h>
|
||||
@ -192,8 +192,14 @@ command_help(int argc, char *argv[])
|
||||
close(hfd);
|
||||
if (!matched) {
|
||||
sprintf(command_errbuf, "no help available for '%s'", topic);
|
||||
free(topic);
|
||||
if (subtopic)
|
||||
free(subtopic);
|
||||
return(CMD_ERROR);
|
||||
}
|
||||
free(topic);
|
||||
if (subtopic)
|
||||
free(subtopic);
|
||||
return(CMD_OK);
|
||||
}
|
||||
|
||||
|
@ -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.15 1999/02/22 13:12:37 dcs Exp $
|
||||
* $Id: interp.c,v 1.16 1999/03/02 16:16:57 dcs Exp $
|
||||
*/
|
||||
/*
|
||||
* Simple commandline interpreter, toplevel and misc.
|
||||
@ -306,11 +306,11 @@ include(char *filename)
|
||||
static void
|
||||
prompt(void)
|
||||
{
|
||||
char *p, *cp, *ev;
|
||||
char *pr, *p, *cp, *ev;
|
||||
|
||||
if ((cp = getenv("prompt")) == NULL)
|
||||
cp = ">";
|
||||
p = strdup(cp);
|
||||
pr = p = strdup(cp);
|
||||
|
||||
while (*p != 0) {
|
||||
if ((*p == '$') && (*(p+1) == '{')) {
|
||||
@ -327,4 +327,5 @@ prompt(void)
|
||||
putchar(*p++);
|
||||
}
|
||||
putchar(' ');
|
||||
free(pr);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
* Jordan K. Hubbard
|
||||
* 29 August 1998
|
||||
*
|
||||
* $Id: interp_parse.c,v 1.5 1999/01/10 05:08:12 msmith Exp $
|
||||
* $Id: interp_parse.c,v 1.6 1999/01/13 08:11:41 msmith Exp $
|
||||
*
|
||||
* The meat of the simple parser.
|
||||
*/
|
||||
@ -167,6 +167,7 @@ parse(int *argc, char ***argv, char *str)
|
||||
*argc = ac;
|
||||
*argv = (char **)malloc((sizeof(char *) * ac + 1));
|
||||
bcopy(args, *argv, sizeof(char *) * ac + 1);
|
||||
free(buf);
|
||||
free(copy);
|
||||
return 0;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user