[common] options: check for realloc failure

This commit is contained in:
Geoffrey McRae 2021-09-11 10:38:07 +10:00
parent 3cefe9f9b5
commit 2aa236e1f9

View File

@ -382,7 +382,16 @@ static char * file_parse_module(FILE * fp)
default: default:
if (len % 32 == 0) if (len % 32 == 0)
module = realloc(module, len + 32 + 1); {
char * p = realloc(module, len + 32 + 1);
if (!p)
{
DEBUG_ERROR("out of memory");
free(module);
return NULL;
}
module = p;
}
module[len++] = c; module[len++] = c;
} }
} }
@ -469,7 +478,16 @@ bool option_load(const char * filename)
} }
if (*len % 32 == 0) if (*len % 32 == 0)
*p = realloc(*p, *len + 32 + 1); {
char * tmp = realloc(*p, *len + 32 + 1);
if (!tmp)
{
DEBUG_ERROR("out of memory");
result = false;
goto exit;
}
*p = tmp;
}
(*p)[(*len)++] = c; (*p)[(*len)++] = c;
break; break;
@ -521,7 +539,16 @@ bool option_load(const char * filename)
} }
if (*len % 32 == 0) if (*len % 32 == 0)
*p = realloc(*p, *len + 32 + 1); {
char * tmp = realloc(*p, *len + 32 + 1);
if (!tmp)
{
DEBUG_ERROR("out of memory");
result = false;
goto exit;
}
*p = tmp;
}
(*p)[(*len)++] = c; (*p)[(*len)++] = c;
break; break;
@ -551,7 +578,16 @@ bool option_load(const char * filename)
break; break;
if (*len % 32 == 0) if (*len % 32 == 0)
*p = realloc(*p, *len + 32 + 1); {
char * tmp = realloc(*p, *len + 32 + 1);
if (!tmp)
{
DEBUG_ERROR("out of memory");
result = false;
goto exit;
}
*p = tmp;
}
(*p)[(*len)++] = c; (*p)[(*len)++] = c;
break; break;
} }