From: Derrick Brashear Date: Sat, 8 Feb 2003 07:30:04 +0000 (+0000) Subject: viced-check-all-malloc-returns-20030208 X-Git-Tag: openafs-devel-1_3_50~390 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=5e2dc3d41cc23499f650a0bd7716381b2a435948;p=packages%2Fo%2Fopenafs.git viced-check-all-malloc-returns-20030208 log something and assert if malloc fails --- diff --git a/src/viced/afsfileprocs.c b/src/viced/afsfileprocs.c index 4ab945b39..227909bfe 100644 --- a/src/viced/afsfileprocs.c +++ b/src/viced/afsfileprocs.c @@ -1842,16 +1842,32 @@ RXGetVolumeStatus(AFSFetchVolumeStatus *status, char **name, char **offMsg, /* now allocate and copy these things; they're freed by the RXGEN stub */ temp = strlen(V_name(volptr)) + 1; *name = malloc(temp); + if (!*name) { + ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n")); + assert(0); + } strcpy(*name, V_name(volptr)); temp = strlen(V_offlineMessage(volptr)) + 1; *offMsg = malloc(temp); + if (!*offMsg) { + ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n")); + assert(0); + } strcpy(*offMsg, V_offlineMessage(volptr)); #if TRANSARC_VOL_STATS *motd = malloc(1); + if (!*motd) { + ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n")); + assert(0); + } strcpy(*motd, nullString); #else temp = strlen(V_motd(volptr)) + 1; *motd = malloc(temp); + if (!*motd) { + ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n")); + assert(0); + } strcpy(*motd, V_motd(volptr)); #endif /* FS_STATS_DETAILED */ @@ -1940,8 +1956,15 @@ static char *AllocSendBuffer() FS_LOCK afs_buffersAlloced++; if (!freeBufferList) { + char *tmp; FS_UNLOCK - return malloc(sendBufSize); + + tmp = malloc(sendBufSize); + if (!tmp) { + ViceLog(0, ("Failed malloc in AllocSendBuffer\n")); + assert(0); + } + return tmp; } tp = freeBufferList; freeBufferList = tp->next; @@ -2330,6 +2353,10 @@ afs_int32 SRXAFS_FetchACL (struct rx_call *acall, AccessList->AFSOpaque_len = 0; AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX); + if (!AccessList->AFSOpaque_val) { + ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n")); + assert(0); + } /* * Get volume/vnode for the fetched file; caller's access rights to it @@ -2507,9 +2534,17 @@ afs_int32 SRXAFS_BulkStatus(struct rx_call *acall, /* allocate space for return output parameters */ OutStats->AFSBulkStats_val = (struct AFSFetchStatus *) malloc(nfiles * sizeof(struct AFSFetchStatus)); + if (!OutStats->AFSBulkStats_val) { + ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n")); + assert(0); + } OutStats->AFSBulkStats_len = nfiles; CallBacks->AFSCBs_val = (struct AFSCallBack *) malloc(nfiles * sizeof(struct AFSCallBack)); + if (!CallBacks->AFSCBs_val) { + ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n")); + assert(0); + } CallBacks->AFSCBs_len = nfiles; if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon))) @@ -2643,9 +2678,17 @@ afs_int32 SRXAFS_InlineBulkStatus(struct rx_call *acall, /* allocate space for return output parameters */ OutStats->AFSBulkStats_val = (struct AFSFetchStatus *) malloc(nfiles * sizeof(struct AFSFetchStatus)); + if (!OutStats->AFSBulkStats_val) { + ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n")); + assert(0); + } OutStats->AFSBulkStats_len = nfiles; CallBacks->AFSCBs_val = (struct AFSCallBack *) malloc(nfiles * sizeof(struct AFSCallBack)); + if (!CallBacks->AFSCBs_val) { + ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n")); + assert(0); + } CallBacks->AFSCBs_len = nfiles; if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon))) { diff --git a/src/viced/callback.c b/src/viced/callback.c index 032a0cf2b..622699890 100644 --- a/src/viced/callback.c +++ b/src/viced/callback.c @@ -518,10 +518,18 @@ int InitCallBack(int nblks) /* N.B. The "-1", below, is because FE[0] and CB[0] are not used--and not allocated */ FE = ((struct FileEntry *)(malloc(sizeof(struct FileEntry)*nblks)))-1; + if (!FE) { + ViceLog(0, ("Failed malloc in InitCallBack\n")); + assert(0); + } cbstuff.nFEs = nblks; while (cbstuff.nFEs) FreeFE(&FE[cbstuff.nFEs]); /* This is correct */ CB = ((struct CallBack *)(malloc(sizeof(struct CallBack)*nblks)))-1; + if (!CB) { + ViceLog(0, ("Failed malloc in InitCallBack\n")); + assert(0); + } cbstuff.nCBs = nblks; while (cbstuff.nCBs) FreeCB(&CB[cbstuff.nCBs]); /* This is correct */ @@ -1886,9 +1894,11 @@ int MultiBreakCallBackAlternateAddress_r(struct host *host, struct AFSCBFids *af i = host->interface->numberOfInterfaces; addr = malloc(i * sizeof(afs_int32)); - if (!addr) return 1; conns = malloc(i * sizeof(struct rx_connection *)); - if (!conns) { free(addr); return 1; } + if (!addr || !conns) { + ViceLog(0, ("Failed malloc in MultiBreakCallBackAlternateAddress_r\n")); + assert(0); + } /* initialize alternate rx connections */ for ( i=0,j=0; i < host->interface->numberOfInterfaces; i++) @@ -1971,10 +1981,12 @@ int MultiProbeAlternateAddress_r(struct host *host) sc = rxnull_NewClientSecurityObject(); i = host->interface->numberOfInterfaces; - addr = malloc(i * sizeof(afs_int32)); - if (!addr) return 1; + addr = malloc(i * sizeof(afs_int32)); conns = malloc(i * sizeof(struct rx_connection *)); - if (!conns) { free(addr); return 1; } + if (!addr || !conns) { + ViceLog(0, ("Failed malloc in MultiProbeAlternateAddress_r\n")); + assert(0); + } /* initialize alternate rx connections */ for ( i=0,j=0; i < host->interface->numberOfInterfaces; i++) diff --git a/src/viced/host.c b/src/viced/host.c index c70deac38..93292baf1 100644 --- a/src/viced/host.c +++ b/src/viced/host.c @@ -545,7 +545,10 @@ struct host *h_Alloc_r(register struct rx_connection *r_con) host = GetHT(); h_hashChain = (struct h_hashChain*) malloc(sizeof(struct h_hashChain)); - assert(h_hashChain); + if (!h_hashChain) { + ViceLog(0, ("Failed malloc in h_Alloc_r\n")); + assert(0); + } h_hashChain->hostPtr = host; h_hashChain->addr = rxr_HostOf(r_con); h_hashChain->next = hostHashTable[index]; @@ -831,9 +834,15 @@ void h_Enumerate(int (*proc)(), char *param) return; } list = (struct host **)malloc(hostCount * sizeof(struct host *)); - assert(list != NULL); + if (!list) { + ViceLog(0, ("Failed malloc in h_Enumerate\n")); + assert(0); + } held = (int *)malloc(hostCount * sizeof(int)); - assert(held != NULL); + if (!held) { + ViceLog(0, ("Failed malloc in h_Enumerate\n")); + assert(0); + } for (count = 0, host = hostList ; host ; host = host->next, count++) { list[count] = host; if (!(held[count] = h_Held_r(host))) @@ -888,6 +897,10 @@ void hashInsertUuid_r(struct afsUUID *uuid, struct host* host) /* insert into beginning of list for this bucket */ chain = (struct h_hashChain *)malloc(sizeof(struct h_hashChain)); + if (!chain) { + ViceLog(0, ("Failed malloc in hashInsertUuid_r\n")); + assert(0); + } assert(chain); chain->hostPtr = host; chain->next = hostUuidHashTable[index]; @@ -936,6 +949,10 @@ retry: H_LOCK if ( code == RXGEN_OPCODE ) { identP = (struct Identity *)malloc(sizeof(struct Identity)); + if (!identP) { + ViceLog(0, ("Failed malloc in h_GetHost_r\n")); + assert(0); + } identP->valid = 0; rx_SetSpecific(tcon, rxcon_ident_key, identP); /* The host on this connection was unable to respond to @@ -955,6 +972,10 @@ retry: } else if (code == 0) { interfValid = 1; identP = (struct Identity *)malloc(sizeof(struct Identity)); + if (!identP) { + ViceLog(0, ("Failed malloc in h_GetHost_r\n")); + assert(0); + } identP->valid = 1; identP->uuid = interf.uuid; rx_SetSpecific(tcon, rxcon_ident_key, identP); @@ -1028,7 +1049,11 @@ retry: code = RXAFSCB_WhoAreYou(host->callback_rxcon, &interf); H_LOCK if ( code == RXGEN_OPCODE ) { - identP = (struct Identity *)malloc(sizeof(struct Identity)); + identP = (struct Identity *)malloc(sizeof(struct Identity)); + if (!identP) { + ViceLog(0, ("Failed malloc in h_GetHost_r\n")); + assert(0); + } identP->valid = 0; rx_SetSpecific(tcon, rxcon_ident_key, identP); ViceLog(25, @@ -1038,6 +1063,10 @@ retry: } else if (code == 0) { interfValid = 1; identP = (struct Identity *)malloc(sizeof(struct Identity)); + if (!identP) { + ViceLog(0, ("Failed malloc in h_GetHost_r\n")); + assert(0); + } identP->valid = 1; identP->uuid = interf.uuid; rx_SetSpecific(tcon, rxcon_ident_key, identP); @@ -1150,6 +1179,10 @@ static int MapName_r(char *aname, char *acell, afs_int32 *aval) } foreign = 1; /* attempt cross-cell authentication */ tname = (char *) malloc(anamelen+cnamelen+2); + if (!tname) { + ViceLog(0, ("Failed malloc in MapName_r\n")); + assert(0); + } strcpy(tname, aname); tname[anamelen] = '@'; strcpy(tname+anamelen+1, acell); @@ -1461,6 +1494,10 @@ char *h_UserName(struct client *client) lids.idlist_len = 1; lids.idlist_val = (afs_int32 *)malloc(1*sizeof(afs_int32)); + if (!lids.idlist_val) { + ViceLog(0, ("Failed malloc in h_UserName\n")); + assert(0); + } lnames.namelist_len = 0; lnames.namelist_val = (prname *)0; lids.idlist_val[0] = client->ViceId; @@ -2027,7 +2064,10 @@ initInterfaceAddr_r(struct host *host, struct interfaceAddr *interf) interface = (struct Interface *) malloc(sizeof(struct Interface) + (sizeof(afs_int32) * (count-1))); - assert(interface); + if (!interface) { + ViceLog(0, ("Failed malloc in initInterfaceAddr_r\n")); + assert(0); + } interface->numberOfInterfaces = count; } else { interface = (struct Interface *) @@ -2063,7 +2103,10 @@ void hashInsert_r(afs_int32 addr, struct host* host) /* insert into beginning of list for this bucket */ chain = (struct h_hashChain *)malloc(sizeof(struct h_hashChain)); - assert(chain); + if (!chain) { + ViceLog(0, ("Failed malloc in hashInsert_r\n")); + assert(0); + } chain->hostPtr = host; chain->next = hostHashTable[index]; chain->addr = addr; @@ -2107,6 +2150,10 @@ addInterfaceAddr_r(struct host *host, afs_int32 addr) interface = (struct Interface *) malloc(sizeof(struct Interface) + (sizeof(afs_int32) * number)); + if (!interface) { + ViceLog(0, ("Failed malloc in addInterfaceAddr_r\n")); + assert(0); + } interface->numberOfInterfaces = number + 1; interface->uuid = host->interface->uuid; for (i = 0 ; i < number ; i++)