Fix potential NULL pointer dereferences
This commit is contained in:
parent
55d89321a0
commit
98c521793e
@ -32,6 +32,11 @@ memfile_t *memfile_creat(const char *name, size_t init)
|
|||||||
mf.offs = 0;
|
mf.offs = 0;
|
||||||
|
|
||||||
pmf = (memfile_t *)malloc(sizeof(memfile_t));
|
pmf = (memfile_t *)malloc(sizeof(memfile_t));
|
||||||
|
if (!pmf)
|
||||||
|
{
|
||||||
|
free(mf.base);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
memcpy(pmf, &mf, sizeof(memfile_t));
|
memcpy(pmf, &mf, sizeof(memfile_t));
|
||||||
|
|
||||||
pmf->name = strdup(name);
|
pmf->name = strdup(name);
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
SC_FUNC char* duplicatestring(const char* sourcestring)
|
SC_FUNC char* duplicatestring(const char* sourcestring)
|
||||||
{
|
{
|
||||||
char* result=(char*)malloc(strlen(sourcestring)+1);
|
char* result=(char*)malloc(strlen(sourcestring)+1);
|
||||||
|
if (result!=NULL)
|
||||||
strcpy(result,sourcestring);
|
strcpy(result,sourcestring);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user