From 99c84c250501a676f73c0dd7e9b842f8c95b1f98 Mon Sep 17 00:00:00 2001 From: Santosh Kumar Pradhan Date: Wed, 29 Jan 2014 17:09:55 +0530 Subject: gNFS: Coverity fix for possible memory leak In nfs_gfid_dict(), if dict_new() fails, the control goes to out: block and dyngfid resource (dynamically allocated by GF_CALLOC()) is leaked. Add a validation for memory returned by GF_CALLOC() Drop unnecessary "goto" statements Coverity CID: 1124764 Change-Id: Idda7923cc1c32260b3353f7a9141aa1cf43e4fe1 BUG: 789278 Signed-off-by: Santosh Kumar Pradhan Reviewed-on: http://review.gluster.org/6852 Reviewed-by: Niels de Vos Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- xlators/nfs/server/src/nfs-fops.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/xlators/nfs/server/src/nfs-fops.c b/xlators/nfs/server/src/nfs-fops.c index 60a5a9a84..14bc0f33b 100644 --- a/xlators/nfs/server/src/nfs-fops.c +++ b/xlators/nfs/server/src/nfs-fops.c @@ -317,6 +317,9 @@ nfs_gfid_dict (inode_t *inode) uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; dyngfid = GF_CALLOC (1, sizeof (uuid_t), gf_common_mt_char); + if (dyngfid == NULL) + return (NULL); + uuid_generate (newgfid); if (uuid_compare (inode->gfid, rootgfid) == 0) @@ -327,16 +330,17 @@ nfs_gfid_dict (inode_t *inode) dictgfid = dict_new (); if (!dictgfid) { gf_log (GF_NFS, GF_LOG_ERROR, "Failed to create gfid dict"); - goto out; + GF_FREE (dyngfid); + return (NULL); } ret = dict_set_bin (dictgfid, "gfid-req", dyngfid, sizeof (uuid_t)); if (ret < 0) { + GF_FREE (dyngfid); dict_unref (dictgfid); - dictgfid = NULL; + return (NULL); } -out: return dictgfid; } -- cgit