LibC: Use FlatPtr for malloced char* address storage

This would break with the next commit, after which char* will always be
treated as c-strings.
This commit is contained in:
Hendiadyoin1 2021-11-08 14:15:13 +01:00 committed by Ali Mohammad Pur
parent ceb0e28ea5
commit dea86f511c
Notes: sideshowbarker 2024-07-17 22:46:59 +09:00

View file

@ -222,14 +222,14 @@ void abort()
_abort();
}
static HashTable<const char*> s_malloced_environment_variables;
static HashTable<FlatPtr> s_malloced_environment_variables;
static void free_environment_variable_if_needed(const char* var)
{
if (!s_malloced_environment_variables.contains(var))
if (!s_malloced_environment_variables.contains((FlatPtr)var))
return;
free(const_cast<char*>(var));
s_malloced_environment_variables.remove(var);
s_malloced_environment_variables.remove((FlatPtr)var);
}
char* getenv(const char* name)
@ -304,7 +304,7 @@ int setenv(const char* name, const char* value, int overwrite)
auto length = strlen(name) + strlen(value) + 2;
auto* var = (char*)malloc(length);
snprintf(var, length, "%s=%s", name, value);
s_malloced_environment_variables.set(var);
s_malloced_environment_variables.set((FlatPtr)var);
return putenv(var);
}