Detect realloc failure 13/13313/3
authorBenjamin Kaduk <kaduk@mit.edu>
Sun, 2 Sep 2018 02:47:39 +0000 (21:47 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Fri, 6 Nov 2020 03:49:43 +0000 (22:49 -0500)
While reviewing other commits, a call to realloc() was discovered that
would leak memory on failure (by virtue of always assigning the realloc()
return value to the pointer holding the input address, even when the
return value is NULL).  Check for failure and return early in that case
(giving an incomplete list of events).

Change-Id: Ic6e889f1d990bd289812ce4bf8e9cd4ebce488ec
Reviewed-on: https://gerrit.openafs.org/13313
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/volser/volprocs.c

index 3b43316..832f5d0 100644 (file)
@@ -2789,6 +2789,7 @@ VolMonitor(struct rx_call *acid, transDebugEntries *transInfo)
 {
     transDebugInfo *pntr;
     afs_int32 allocSize = 50;
+    afs_int32 code = 0;
     struct volser_trans *tt, *nt, *allTrans;
 
     if (!afsconf_CheckRestrictedQuery(tdir, acid, restrictedQueryLevel))
@@ -2832,6 +2833,10 @@ VolMonitor(struct rx_call *acid, transDebugEntries *transInfo)
            allocSize = (allocSize * 3) / 2;
            pntr = realloc(transInfo->transDebugEntries_val,
                           allocSize * sizeof(transDebugInfo));
+           if (pntr == NULL) {
+               code = ENOMEM;
+               goto done;
+           }
            transInfo->transDebugEntries_val = pntr;
            pntr =
                transInfo->transDebugEntries_val +
@@ -2843,7 +2848,7 @@ VolMonitor(struct rx_call *acid, transDebugEntries *transInfo)
 done:
     VTRANS_UNLOCK;
 
-    return 0;
+    return code;
 }
 
 afs_int32