1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-20 04:48:06 +01:00

real_main: Use setenv() instead of putenv()

When investigating possible memory leaks with 'valgrind' I noticed
this leak report:

 602 bytes in 13 blocks are definitely lost in loss record 77 of 128
    at 0x4C2362E: malloc (vg_replace_malloc.c:207)
    by 0x4576ED: wmalloc (memory.c:88)
    by 0x45B4F7: wstrconcat (string.c:214)
    by 0x426FC2: main (main.c:608)

which happens here,

    str = wstrconcat("WMAKER_BIN_NAME=", argv[0]);
    putenv(str);

There is a comment further below (in another context)

/* return of wstrconcat should not be free-ed! read putenv man page */

so this leak report is probably a false positive anyway. However,
https://www.securecoding.cert.org/confluence/display/seccode/POS34-C.+Do+not+call+putenv%28%29+with+a+pointer+to+an+automatic+variable+as+the+argument
has some nice discussion about putenv() and after reading it I decided to
use setenv() instead, making 'valgrind' happy along the way. It also
makes the code a bit simpler, avoiding a call to wstrconcat().

I also changed the name of another variable called 'str' to 'pos', just
in case.
This commit is contained in:
Carlos R. Mafra
2009-08-17 22:03:28 +02:00
parent 7a84127a27
commit 6310e40d47

View File

@@ -593,7 +593,7 @@ static int
real_main(int argc, char **argv)
{
int i, restart=0;
char *str;
char *str, *pos;
int d, s;
int flag;
#ifdef DEBUG
@@ -604,9 +604,7 @@ real_main(int argc, char **argv)
wsetabort(wAbort);
/* for telling WPrefs what's the name of the wmaker binary being ran */
str = wstrconcat("WMAKER_BIN_NAME=", argv[0]);
putenv(str);
setenv("WMAKER_BIN_NAME", argv[0], 1);
flag= 0;
ArgCount = argc;
@@ -787,11 +785,11 @@ real_main(int argc, char **argv)
/* check if the user specified a complete display name (with screen).
* If so, only manage the specified screen */
if (DisplayName)
str = strchr(DisplayName, ':');
pos = strchr(DisplayName, ':');
else
str = NULL;
pos = NULL;
if (str && sscanf(str, ":%i.%i", &d, &s)==2)
if (pos && sscanf(pos, ":%i.%i", &d, &s)==2)
multiHead = False;
DisplayName = XDisplayName(DisplayName);