From d55a5d70802a1907ef7cf9c9d20646cb69e89989 Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Sat, 31 Mar 2012 14:42:39 -0400 Subject: [PATCH] pts: Don't malloc(0) when there's nothing to do If GetNameOrId is called with no work to do, then don't attempt to malloc a load of 0 length strings. Instead just return an empty array to the caller. Change-Id: I245cfde71d65b8a3b6df4217b90dad81e9e60a58 Reviewed-on: http://gerrit.openafs.org/7100 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- src/ptserver/pts.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ptserver/pts.c b/src/ptserver/pts.c index 276ff7b2f..b6601d6d7 100644 --- a/src/ptserver/pts.c +++ b/src/ptserver/pts.c @@ -471,16 +471,26 @@ GetNameOrId(struct cmd_syndesc *as, struct idlist *lids, struct idlist ids, tids; /* local copy, if not ret. ids */ int goodCount = 0; + /* Initialise our outputs */ + memset(lids, 0, sizeof(struct idlist)); + if (lnames) + memset(lnames, 0, sizeof(struct namelist)); + for (i = as->parms[0].items; i; i = i->next) n++; - lids->idlist_val = (afs_int32 *) malloc(n * sizeof(afs_int32)); + + /* Nothing to do, so bail */ + if (n == 0) + return 0; + + lids->idlist_val = malloc(n * sizeof(afs_int32)); lids->idlist_len = n; - ids.idlist_val = (afs_int32 *) malloc(n * sizeof(afs_int32)); + ids.idlist_val = malloc(n * sizeof(afs_int32)); ids.idlist_len = n; - names.namelist_val = (prname *) malloc(n * PR_MAXNAMELEN); + names.namelist_val = malloc(n * PR_MAXNAMELEN); names.namelist_len = n; if (lnames) { - lnames->namelist_val = (prname *) malloc(n * PR_MAXNAMELEN); + lnames->namelist_val = malloc(n * PR_MAXNAMELEN); lnames->namelist_len = 0; } for (i = as->parms[0].items; i; i = i->next) { -- 2.39.5