From 4c93dcf3d3467422215b0313a89ca34c60122e03 Mon Sep 17 00:00:00 2001 From: kcwu Date: Thu, 24 Feb 2005 18:56:28 +0000 Subject: use only single malloc in initsetproctitle() git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2538 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/args.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'mbbsd/args.c') diff --git a/mbbsd/args.c b/mbbsd/args.c index 32156517..8d6ee98d 100644 --- a/mbbsd/args.c +++ b/mbbsd/args.c @@ -18,15 +18,23 @@ void initsetproctitle(int argc, char **argv, char **envp) { register int i; + int len=0,nenv=0; /* * Move the environment so setproctitle can use the space at the top of * memory. */ - for (i = 0; envp[i]; i++); - environ = malloc(sizeof(char *) * (i + 1)); for (i = 0; envp[i]; i++) - environ[i] = strdup(envp[i]); + len+=strlen(envp[i])+1; + nenv=i+1; + len+=sizeof(char*)*nenv; + environ = malloc(len); + len=0; + for (i = 0; envp[i]; i++) { + environ[i] = (char*)environ+nenv*sizeof(char*)+len; + strcpy(environ[i], envp[i]); + len+=strlen(envp[i])+1; + } environ[i] = NULL; /* Save start and extent of argv for setproctitle. */ -- cgit v1.2.3