Changed all remaining mallocs to callocs.

git-svn-id: svn://opensvn.adaptivecomputing.com/maui/trunk@143 3f5042e3-fb1d-0410-be18-d6ca2573e517
This commit is contained in:
jasonw 2010-08-06 13:36:50 +00:00
parent 8ed8a5727c
commit 2c93b33b5f
11 changed files with 63 additions and 64 deletions

View File

@ -285,8 +285,9 @@ int __MGSSGetToken(
len |= ((size_t) buffer[1]) << 16;
len |= ((size_t) buffer[2]) << 8;
len |= ((size_t) buffer[3]);
tok = malloc(len);
tok = calloc(len, 1);
if (!tok)
{

View File

@ -1760,8 +1760,7 @@ int MSURecvData(
return(FAILURE);
}
if ((S->RBuffer = (char *)malloc(S->RBufSize + 1)) == NULL)
if ((S->RBuffer = (char *)calloc(S->RBufSize + 1, 1)) == NULL)
{
MDB(1,fSOCK) MLog("ERROR: cannot allocate buffer space (%ld bytes requested) errno: %d (%s)\n",
S->RBufSize,
@ -1812,8 +1811,7 @@ int MSURecvData(
/* allocate large receive space */
S->RBufSize = MMAX_BUFFER << 4;
if ((S->RBuffer = (char *)malloc(S->RBufSize + 1)) == NULL)
if ((S->RBuffer = (char *)calloc(S->RBufSize + 1, 1)) == NULL)
{
MDB(1,fSOCK) MLog("ERROR: cannot allocate buffer space (%ld bytes requested) errno: %d (%s)\n",
S->RBufSize,
@ -1969,8 +1967,7 @@ int MSURecvData(
if (S->RBuffer == NULL)
{
/* allocate receive space */
if ((S->RBuffer = (char *)malloc(S->RBufSize + 1)) == NULL)
if ((S->RBuffer = (char *)calloc(S->RBufSize + 1, 1)) == NULL)
{
MDB(1,fSOCK) MLog("ERROR: cannot allocate buffer space (%ld bytes requested) errno: %d (%s)\n",
S->RBufSize,
@ -2123,8 +2120,7 @@ int MSURecvData(
return(FAILURE);
}
if ((S->RBuffer = (char *)malloc(S->RBufSize + 1)) == NULL)
if ((S->RBuffer = (char *)calloc(S->RBufSize + 1, 1)) == NULL)
{
MDB(1,fSOCK) MLog("ERROR: cannot allocate buffer space (%ld bytes requested) errno: %d (%s)\n",
S->RBufSize,
@ -3919,7 +3915,7 @@ int MSUAdjustSBuffer(
if (S->SBIsDynamic == FALSE)
{
ptr = (char *)malloc(NewSize);
ptr = (char *)calloc(NewSize, 1);
memcpy(ptr,S->SBuffer,S->SBufSize);
}
@ -4055,8 +4051,7 @@ int MSUDup(
}
/* do shallow memcpy first */
S = (msocket_t *)malloc(sizeof(msocket_t));
S = (msocket_t *)calloc(1,sizeof(msocket_t));
memcpy(S,Src,sizeof(msocket_t));

View File

@ -350,7 +350,7 @@ int MSecGetChecksum2(
/* NOTE: merge header and data */
ptr = (char *)malloc(BufSize1 + BufSize2);
ptr = (char *)calloc(BufSize1 + BufSize2, 1);
strcpy(ptr,Buf1);
strcpy(ptr + BufSize1,Buf2);
@ -378,7 +378,8 @@ int MSecGetChecksum2(
/* NOTE: merge header and data */
ptr = (char *)malloc(BufSize1 + BufSize2);
ptr = (char *)calloc(BufSize1 + BufSize2, 1);
strcpy(ptr,Buf1);
strcpy(ptr + BufSize1,Buf2);
@ -406,7 +407,8 @@ int MSecGetChecksum2(
/* NOTE: merge header and data */
ptr = (char *)malloc(BufSize1 + BufSize2);
ptr = (char *)calloc(BufSize1 + BufSize2, 1);
strcpy(ptr,Buf1);
strcpy(ptr + BufSize1,Buf2);
@ -1628,7 +1630,7 @@ int MSecCompress(
if (LocalDstString == NULL)
{
LocalDstString = (char *)malloc(NewLength);
LocalDstString = (char *)calloc(NewLength, 1);
LocalDstSize = NewLength;
}
@ -1789,7 +1791,7 @@ int MSecDecompress(
else if (DDstBuf != NULL)
{
if ((OutBuf == NULL) &&
((OutBuf = (unsigned char *)malloc(MMAX_BUFFER)) == NULL))
((OutBuf = (unsigned char *)calloc(MMAX_BUFFER, 1)) == NULL))
{
return(FAILURE);
}
@ -1814,7 +1816,7 @@ int MSecDecompress(
if (tmpBuf == NULL)
{
if ((tmpBuf = (unsigned char *)malloc(NewLength)) == NULL)
if ((tmpBuf = (unsigned char *)calloc(NewLength, 1)) == NULL)
{
return(FAILURE);
}

View File

@ -43,8 +43,7 @@ comm_thread_t* comm_thread_new(
{
comm_thread_t* thread;
if ((thread = (comm_thread_t *)malloc(sizeof(comm_thread_t))) == NULL)
if ((thread = (comm_thread_t *)calloc(1,sizeof(comm_thread_t))) == NULL)
{
return(NULL);
}
@ -53,8 +52,7 @@ comm_thread_t* comm_thread_new(
thread->read_handler = NULL;
thread->close_handler = NULL;
thread->error_handler = NULL;
thread->connection = (communication_t **)malloc(max_connections * sizeof(void*));
thread->connection = (communication_t **)calloc(max_connections, sizeof(void*));
thread->connections = 0;
thread->max_connections = max_connections;
@ -244,8 +242,7 @@ communication_t *communication_new(
{
communication_t *comm;
if ((comm = (communication_t *)malloc(sizeof(communication_t))) == NULL)
if ((comm = (communication_t *)calloc(1, sizeof(communication_t))) == NULL)
{
return(NULL);
}

View File

@ -632,8 +632,7 @@ int MXMLToXString(
if (*Buf == NULL)
{
NewSize = MMAX_BUFFER;
if ((*Buf = (char *)malloc(NewSize)) == NULL)
if ((*Buf = (char *)calloc(NewSize, 1)) == NULL)
{
/* cannot allocate buffer */

View File

@ -107,15 +107,14 @@ char *MFULoad(
else
{
/* copy cached data */
if ((ptr = (char *)malloc(BufSize + 1)) == NULL)
if ((ptr = (char *)calloc(BufSize + 1, 1)) == NULL)
{
MOSSyslog(LOG_ERR,"cannot malloc buffer for file '%s', errno: %d (%s)",
MOSSyslog(LOG_ERR,"cannot calloc buffer for file '%s', errno: %d (%s)",
FileName,
errno,
strerror(errno));
DBG(2,fCORE) DPrint("ERROR: cannot malloc file buffer for file '%s', errno: %d (%s)\n",
DBG(2,fCORE) DPrint("ERROR: cannot calloc file buffer for file '%s', errno: %d (%s)\n",
FileName,
errno,
strerror(errno));
@ -127,7 +126,7 @@ char *MFULoad(
}
else
{
/* fill malloc'd buffer */
/* fill calloc'd buffer */
memcpy(ptr,buf,BufSize + 1);
@ -190,16 +189,15 @@ char *MFULoad(
FileName,
BufSize,
ReadCount);
if ((ptr = (char *)malloc(BufSize + 1)) == NULL)
if ((ptr = (char *)calloc(BufSize + 1,1)) == NULL)
{
MOSSyslog(LOG_ERR,"cannot malloc %d byte buffer for file '%s', errno: %d (%s)",
MOSSyslog(LOG_ERR,"cannot calloc %d byte buffer for file '%s', errno: %d (%s)",
BufSize,
FileName,
errno,
strerror(errno));
DBG(2,fCORE) DPrint("ERROR: cannot malloc file buffer for file '%s', errno: %d (%s)\n",
DBG(2,fCORE) DPrint("ERROR: cannot calloc file buffer for file '%s', errno: %d (%s)\n",
FileName,
errno,
strerror(errno));
@ -405,15 +403,14 @@ int __MFUCacheFile(
MFileCache[index].Buffer = NULL;
}
if ((MFileCache[index].Buffer = (char *)malloc(BufSize + 1)) == NULL)
if ((MFileCache[index].Buffer = (char *)calloc(BufSize + 1, 1)) == NULL)
{
MOSSyslog(LOG_ERR,"cannot malloc cache buffer for file '%s', errno: %d (%s)",
MOSSyslog(LOG_ERR,"cannot calloc cache buffer for file '%s', errno: %d (%s)",
FileName,
errno,
strerror(errno));
DBG(2,fSTRUCT) DPrint("ERROR: cannot malloc file buffer for file '%s', errno: %d (%s)\n",
DBG(2,fSTRUCT) DPrint("ERROR: cannot calloc file buffer for file '%s', errno: %d (%s)\n",
FileName,
errno,
strerror(errno));
@ -447,16 +444,16 @@ int __MFUCacheFile(
{
if (MFileCache[index].FileName[0] == '\0')
{
/* malloc space for buffer */
/* calloc space for buffer */
if ((MFileCache[index].Buffer = (char *)malloc(BufSize + 1)) == NULL)
if ((MFileCache[index].Buffer = (char *)calloc(BufSize + 1, 1)) == NULL)
{
MOSSyslog(LOG_ERR,"cannot malloc cache buffer for file '%s', errno: %d (%s)",
MOSSyslog(LOG_ERR,"cannot calloc cache buffer for file '%s', errno: %d (%s)",
FileName,
errno,
strerror(errno));
DBG(2,fSTRUCT) DPrint("ERROR: cannot malloc cache buffer for file '%s', errno: %d (%s)\n",
DBG(2,fSTRUCT) DPrint("ERROR: cannot calloc cache buffer for file '%s', errno: %d (%s)\n",
FileName,
errno,
strerror(errno));
@ -752,14 +749,14 @@ int MFUGetRecord(
}
else if (!strcmp(Index[index].Key,Key))
{
if ((*Buffer = (char *)malloc(RecSize)) == NULL)
if ((*Buffer = (char *)calloc(RecSize, 1)) == NULL)
{
MOSSyslog(LOG_ERR,"cannot malloc buffer for record '%s', errno: %d (%s)",
MOSSyslog(LOG_ERR,"cannot calloc buffer for record '%s', errno: %d (%s)",
Key,
errno,
strerror(errno));
DBG(2,fCORE) DPrint("ERROR: cannot malloc %d buffer for record '%s', errno: %d (%s)\n",
DBG(2,fCORE) DPrint("ERROR: cannot calloc %d buffer for record '%s', errno: %d (%s)\n",
RecSize,
Key,
errno,
@ -790,13 +787,13 @@ int MFUGetRecord(
return(SUCCESS);
}
if ((*Buffer = (char *)malloc(rcount * RecSize)) == NULL)
if ((*Buffer = (char *)calloc(rcount, RecSize)) == NULL)
{
MOSSyslog(LOG_ERR,"cannot malloc buffer for all records, errno: %d (%s)",
MOSSyslog(LOG_ERR,"cannot calloc buffer for all records, errno: %d (%s)",
errno,
strerror(errno));
DBG(2,fCORE) DPrint("ERROR: cannot malloc %d byte buffer for all records, errno: %d (%s)\n",
DBG(2,fCORE) DPrint("ERROR: cannot calloc %d byte buffer for all records, errno: %d (%s)\n",
rcount * RecSize,
errno,
strerror(errno));

View File

@ -86,7 +86,7 @@ int MNodeCreate(
if (*NP == NULL)
{
*NP = (mnode_t *)malloc(sizeof(mnode_t));
*NP = (mnode_t *)calloc(1, sizeof(mnode_t));
N = *NP;

View File

@ -232,7 +232,7 @@ int MJobSelectPJobList(
if (PreempteeTaskList != NULL)
{
pJ[index].TL = (nodelist_t *)malloc(sizeof(nodelist_t));
pJ[index].TL = (nodelist_t *)calloc(1, sizeof(nodelist_t));
memcpy(pJ[index].TL,&tmpTaskList,sizeof(mnalloc_t) * (tindex + 1));
}

View File

@ -2900,11 +2900,19 @@ int MNodeBuildRE(
memset(&ZRes,0,sizeof(ZRes));
CRE = (mre_t *)malloc(sizeof(mre_t) * ((MAX_MRES_DEPTH << 1) + 1));
ORE = (mre_t *)malloc(sizeof(mre_t) * ((MAX_MRES_DEPTH << 1) + 1));
NRE = (mre_t *)malloc(sizeof(mre_t) * ((MAX_MRES_DEPTH << 1) + 1));
JRE = (mre_t *)malloc(sizeof(mre_t) * ((MAX_MRES_DEPTH << 1) + 1));
CRE = (mre_t *)calloc(((MAX_MRES_DEPTH << 1) + 1), sizeof(mre_t));
ORE = (mre_t *)calloc(((MAX_MRES_DEPTH << 1) + 1), sizeof(mre_t));
NRE = (mre_t *)calloc(((MAX_MRES_DEPTH << 1) + 1), sizeof(mre_t));
JRE = (mre_t *)calloc(((MAX_MRES_DEPTH << 1) + 1), sizeof(mre_t));
if (CRE == NULL || ORE == NULL || NRE == NULL || JRE == NULL )
{
DBG(4,fCORE) DPrint("ALERT: cannot allocate memory in %s\n",
FName);
return(FAILURE);
}
CRI[0] = -1;
ResFound = FALSE;

View File

@ -3923,9 +3923,9 @@ int MUDStatInitialize(
D->DSize = DSize;
D->Count = 0;
if ((D->Data = (char *)malloc(DSize * DSTAT_STEPSIZE)) == NULL)
if ((D->Data = (char *)calloc(DSTAT_STEPSIZE, DSize)) == NULL)
{
DBG(0,fCORE) DPrint("ALERT: cannot malloc memory for dstat\n");
DBG(0,fCORE) DPrint("ALERT: cannot calloc memory for dstat\n");
return(FAILURE);
}
@ -5269,7 +5269,7 @@ char *MUURLCreate(
BPtr = Buf;
BSpace = BufSize;
}
else if ((BPtr = malloc(MAX_MLINE)) != NULL)
else if ((BPtr = calloc(MAX_MLINE, 1)) != NULL)
{
BSpace = BufSize;
}

View File

@ -2598,7 +2598,7 @@ int MCShowCStats(
case mxoUser:
if (OCount == 0)
tmpU = (mgcred_t *)malloc(sizeof(mgcred_t) * MAX_MUSER);
tmpU = (mgcred_t *)calloc(MAX_MUSER, sizeof(mgcred_t));
O = &tmpU[OCount + 1];
@ -2609,7 +2609,7 @@ int MCShowCStats(
case mxoGroup:
if (OCount == 0)
tmpG = (mgcred_t *)malloc(sizeof(mgcred_t) * MAX_MGROUP);
tmpG = (mgcred_t *)calloc(MAX_MGROUP,sizeof(mgcred_t));
O = &tmpG[OCount + 1];
@ -2618,7 +2618,7 @@ int MCShowCStats(
case mxoAcct:
if (OCount == 0)
tmpA = (mgcred_t *)malloc(sizeof(mgcred_t) * MAX_MACCT);
tmpA = (mgcred_t *)calloc(MAX_MACCT, sizeof(mgcred_t));
O = &tmpA[OCount + 1];
@ -2627,7 +2627,7 @@ int MCShowCStats(
case mxoClass:
if (OCount == 0)
tmpC = (mclass_t *)malloc(sizeof(mclass_t) * MAX_MCLASS);
tmpC = (mclass_t *)calloc(MAX_MCLASS, sizeof(mclass_t));
O = &tmpC[OCount + 1];
@ -2636,7 +2636,7 @@ int MCShowCStats(
case mxoQOS:
if (OCount == 0)
tmpQ = (mqos_t *)malloc(sizeof(mqos_t) * MAX_MQOS);
tmpQ = (mqos_t *)calloc(MAX_MQOS, sizeof(mqos_t));
O = &tmpQ[OCount + 1];