Memory allocation checks.

This commit is contained in:
Andrew Johnson
2009-05-05 15:19:00 +00:00
parent 42f0106d48
commit 8ee39f8cce
2 changed files with 17 additions and 3 deletions

View File

@@ -277,6 +277,15 @@ int epicsShareAPI dbLoadTemplate(char* sub_file)
vars = (char**)malloc(VAR_MAX_VARS * sizeof(char*));
sub_collect = malloc(VAR_MAX_VAR_STRING);
if (!vars || !sub_collect)
{
free(vars);
free(sub_collect);
fclose(fp);
fprintf(stderr, "dbLoadTemplate: Out of memory!\n");
return -1;
}
sub_collect[0]='\0';
var_count=0;
sub_count=0;

View File

@@ -3,8 +3,7 @@
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
@@ -121,7 +120,13 @@ void* epicsShareAPI dbmfMalloc(size_t size)
pitemHeader = (itemHeader *)pnextFree;
pitemHeader->pchunkNode->nNotFree += 1;
} else {
pmem = malloc(sizeof(itemHeader) + size); pdbmfPvt->nAlloc++;
pmem = malloc(sizeof(itemHeader) + size);
if(!pmem) {
epicsMutexUnlock(pdbmfPvt->lock);
printf("dbmfMalloc malloc failed\n");
return(NULL);
}
pdbmfPvt->nAlloc++;
pdbmfPvt->nGtSize++;
pitemHeader = (itemHeader *)pmem;
pitemHeader->pchunkNode = NULL;