bucoord: Don't malloc(0) if there's no work to do
authorSimon Wilkinson <sxw@your-file-system.com>
Sat, 31 Mar 2012 18:37:04 +0000 (14:37 -0400)
committerDerrick Brashear <shadow@dementix.org>
Mon, 9 Apr 2012 01:20:55 +0000 (18:20 -0700)
If there's no work to do, then don't attempt to malloc 0 bytes, and
just return success to the user

Change-Id: I060852a247acb8309c75f3670577561b5a9af591
Reviewed-on: http://gerrit.openafs.org/7099
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>

src/bucoord/dump.c

index 3c67a7f..5d1f58a 100644 (file)
@@ -51,7 +51,7 @@ bc_Dumper(int aindex)
     struct rx_connection *tconn;
     struct bc_volumeDump *tde;
     afs_int32 count, port;
-    struct tc_dumpDesc *volDesc = 0;
+    struct tc_dumpDesc *volDesc = NULL;
     struct tc_dumpArray volArray;
     char *baseNamePtr;
     statusP statusPtr;
@@ -78,8 +78,12 @@ bc_Dumper(int aindex)
      */
     for (count = 0, tde = dumpTaskPtr->volumes; tde;
         tde = tde->next, count++);
-    volDesc =
-       (struct tc_dumpDesc *)malloc(count * sizeof(struct tc_dumpDesc));
+
+    /* Nothing to dump, so just return success */
+    if (count == 0)
+       goto error_exit;
+
+    volDesc = malloc(count * sizeof(struct tc_dumpDesc));
     if (!volDesc) {
        afs_com_err(whoami, BC_NOMEM, NULL);
        ERROR(BC_NOMEM);