Don't allocate objects of 0 length
[openafs.git] / src / libadmin / vos / vosutils.c
index 3fcab99..b00cc4a 100644 (file)
@@ -277,22 +277,25 @@ VLDB_ListAttributes(afs_cell_handle_p cellHandle,
                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;
            }
        }