/* Allocate space for the return values if needed and zero it */
if (eList->budb_dumpList_val == 0) {
- eList->budb_dumpList_val = calloc(to_return, e_size);
- if (!eList->budb_dumpList_val)
- return (BUDB_NOMEM);
+ if (to_return > 0) {
+ eList->budb_dumpList_val = calloc(to_return, e_size);
+ if (!eList->budb_dumpList_val)
+ return (BUDB_NOMEM);
+ } else
+ eList->budb_dumpList_val = NULL;
} else {
memset(eList->budb_dumpList_val, 0, e_size * to_return);
}
if (*entriesp > arrayEntries.bulkentries_len)
*entriesp = arrayEntries.bulkentries_len;
- blkentriesp->nbulkentries_val =
- malloc(*entriesp * sizeof(*blkentriesp));
- if (blkentriesp->nbulkentries_val != NULL) {
- for (i = 0; i < *entriesp; i++) {
- OldVLDB_to_NewVLDB((struct vldbentry *)&arrayEntries.
- bulkentries_val[i],
- (struct nvldbentry *)&blkentriesp->
- nbulkentries_val[i], &tst);
+ if (*entriesp > 0) {
+ blkentriesp->nbulkentries_val =
+ calloc(*entriesp, sizeof(*blkentriesp));
+ if (blkentriesp->nbulkentries_val != NULL) {
+ for (i = 0; i < *entriesp; i++) {
+ OldVLDB_to_NewVLDB((struct vldbentry *)&arrayEntries.
+ bulkentries_val[i],
+ (struct nvldbentry *)&blkentriesp->
+ nbulkentries_val[i], &tst);
+ }
+ } else {
+ tst = ADMNOMEM;
}
} else {
- tst = ADMNOMEM;
- }
- if (arrayEntries.bulkentries_val) {
- free(arrayEntries.bulkentries_val);
+ blkentriesp->nbulkentries_val = NULL;
}
+ xdr_free((xdrproc_t)xdr_bulkentries, &arrayEntries);
+
rc = 1;
}
}
numSmallVnodes = numFileVnodes;
} else {
- LargeVnodeIndex = (struct vnodeData **)
- malloc(numDirVnodes * sizeof(struct vnodeData));
- SmallVnodeIndex = (struct vnodeData **)
- malloc(numFileVnodes * sizeof(struct vnodeData));
+ if (numDirVnodes == 0)
+ LargeVnodeIndex = NULL;
+ else
+ LargeVnodeIndex = malloc(numDirVnodes
+ * sizeof(struct vnodeData *));
+ if (numFileVnodes == 0)
+ SmallVnodeIndex = NULL;
+ else
+ SmallVnodeIndex = malloc(numFileVnodes
+ * sizeof(struct vnodeData *));
- if (LargeVnodeIndex == NULL || SmallVnodeIndex == NULL) {
+ if ((numDirVnodes != 0 && LargeVnodeIndex == NULL) ||
+ (numFileVnodes != 0 && SmallVnodeIndex == NULL)) {
if (verbose)
fprintf(stderr,
"Unable to allocate space " "for vnode tables\n");
int
InitCallBack(int nblks)
{
+ opr_Assert(nblks > 0);
+
H_LOCK;
tfirst = CBtime(time(NULL));
/* N.B. The "-1", below, is because
* FE[0] and CB[0] are not used--and not allocated */
- FE = ((struct FileEntry *)(calloc(nblks, sizeof(struct FileEntry))));
+ FE = calloc(nblks, sizeof(struct FileEntry));
if (!FE) {
ViceLogThenPanic(0, ("Failed malloc in InitCallBack\n"));
}
cbstuff.nFEs = nblks;
while (cbstuff.nFEs)
FreeFE(&FE[cbstuff.nFEs]); /* This is correct */
- CB = ((struct CallBack *)(calloc(nblks, sizeof(struct CallBack))));
+ CB = calloc(nblks, sizeof(struct CallBack));
if (!CB) {
ViceLogThenPanic(0, ("Failed malloc in InitCallBack\n"));
}
if (debugging_on)
printf("%s: Allocating socket array for %d Cache Manager(s)\n", rn,
numCMs);
- CMSktArray = malloc(numCMs * sizeof(struct sockaddr_in));
- if (CMSktArray == (struct sockaddr_in *)0) {
- printf("%s: Can't allocate socket array for %d Cache Managers\n", rn,
- numCMs);
- exit(1);
+ if (numCMs > 0) {
+ CMSktArray = calloc(numCMs, sizeof(struct sockaddr_in));
+ if (CMSktArray == NULL) {
+ printf("%s: Can't allocate socket array for %d Cache Managers\n",
+ rn, numCMs);
+ exit(1);
+ }
+ } else {
+ CMSktArray = NULL;
}
/*
*/
if (debugging_on)
printf("Allocating %d long(s) for coll ID\n", numCollIDs);
- collIDP = malloc(numCollIDs * sizeof(afs_int32));
+
+ if (numCollIDs > 0)
+ collIDP = calloc(numCollIDs, sizeof(afs_int32));
+ else
+ collIDP = NULL;
+
currCollIDP = collIDP;
curr_item = a_s->parms[P_COLL_IDS].items;
for (currCollIDIdx = 0; currCollIDIdx < numCollIDs; currCollIDIdx++) {
*/
if (debugging_on)
printf("Allocating %d long(s) for coll ID\n", numCollIDs);
- collIDP = malloc(numCollIDs * sizeof(afs_int32));
+
+ if (numCollIDs > 0)
+ collIDP = calloc(numCollIDs, sizeof(afs_int32));
+ else
+ collIDP = NULL;
+
currCollIDP = collIDP;
curr_item = a_s->parms[P_COLL_IDS].items;
for (currCollIDIdx = 0; currCollIDIdx < numCollIDs; currCollIDIdx++) {