add_variable() just threw away the freshly copied environment (makes me
wonder why things worked nevertheless with the old gcc). We now also use realloc() instead of malloc()+memcpy(), and check add_variable()'s return code. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14957 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -44,14 +44,15 @@ static int32
|
|||||||
add_variable(void)
|
add_variable(void)
|
||||||
{
|
{
|
||||||
int32 count = count_variables() + 1;
|
int32 count = count_variables() + 1;
|
||||||
char **newEnv = malloc((count + 1) * sizeof(char *));
|
char **newEnv = realloc(environ, (count + 1) * sizeof(char *));
|
||||||
if (newEnv == NULL)
|
if (newEnv == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
memcpy(newEnv, environ, count * sizeof(char *));
|
|
||||||
newEnv[count] = NULL;
|
newEnv[count] = NULL;
|
||||||
// null terminate the array
|
// null terminate the array
|
||||||
|
|
||||||
|
environ = newEnv;
|
||||||
|
|
||||||
return count - 1;
|
return count - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +119,10 @@ update_variable(const char *name, int32 length, const char *value, bool overwrit
|
|||||||
} else if (env == NULL) {
|
} else if (env == NULL) {
|
||||||
// add variable
|
// add variable
|
||||||
index = add_variable();
|
index = add_variable();
|
||||||
update = true;
|
if (index >= 0)
|
||||||
|
update = true;
|
||||||
|
else
|
||||||
|
status = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
|
|||||||
Reference in New Issue
Block a user