Check for failure in allocations.

This commit is contained in:
Hisham
2016-02-02 15:53:02 +01:00
parent a1f7f2869e
commit b54d2dde40
42 changed files with 141 additions and 134 deletions

View File

@ -220,16 +220,16 @@ char* Platform_getProcessEnv(pid_t pid) {
char *env = NULL;
if (fd) {
size_t capacity = 4096, size = 0, bytes;
env = malloc(capacity);
env = xMalloc(capacity);
while (env && (bytes = fread(env+size, 1, capacity-size, fd)) > 0) {
size += bytes;
capacity *= 2;
env = realloc(env, capacity);
env = xRealloc(env, capacity);
}
fclose(fd);
if (size < 2 || env[size-1] || env[size-2]) {
if (size + 2 < capacity) {
env = realloc(env, capacity+2);
env = xRealloc(env, capacity+2);
}
env[size] = 0;
env[size+1] = 0;