summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2010-07-06 12:48:01 -0500
committerNoriko Hosoi <nhosoi@redhat.com>2010-08-23 17:08:55 -0700
commite63bd50a2ee4de726c29ad656335c456b900ed9a (patch)
tree09b304de64bce7ad8c9a114e253d45ddb079cc3d /lib
parent93d53d5e11c89fd745c267e27b04bb08497a057a (diff)
downloadds-e63bd50a2ee4de726c29ad656335c456b900ed9a.tar.gz
ds-e63bd50a2ee4de726c29ad656335c456b900ed9a.tar.xz
ds-e63bd50a2ee4de726c29ad656335c456b900ed9a.zip
Bug 611790 - fix coverify Defect Type: Null pointer dereferences issues 11940 - 12166
https://bugzilla.redhat.com/show_bug.cgi?id=611790 Resolves: bug 611790 Bug description: Fix coverify Defect Type: Null pointer dereferences issues 11940 - 12166 Fix description: Catch possible NULL pointer in ResHashCreate().
Diffstat (limited to 'lib')
-rw-r--r--lib/libsi18n/reshash.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/libsi18n/reshash.c b/lib/libsi18n/reshash.c
index 898d02f5..4c8e9006 100644
--- a/lib/libsi18n/reshash.c
+++ b/lib/libsi18n/reshash.c
@@ -253,7 +253,7 @@ ResHash * ResHashCreate(char * name)
/* Create hash table */
pResHash = (ResHash *) malloc (sizeof(ResHash));
if (pResHash == NULL)
- return NULL;
+ goto error;
memset(pResHash, 0, sizeof(ResHash));
@@ -262,11 +262,26 @@ ResHash * ResHashCreate(char * name)
/* Create initial tree item and it's valuelist to hash table */
pResHash->treelist = (TreeNode *) malloc(sizeof(TreeNode));
- if (pResHash->treelist)
- memset(pResHash->treelist, 0, sizeof(TreeNode));
+ if (pResHash->treelist == NULL)
+ goto error;
+
+ memset(pResHash->treelist, 0, sizeof(TreeNode));
+
pResHash->treelist->vlist = (ValueNode *) malloc(sizeof(ValueNode));
+ if (pResHash->treelist->vlist == NULL)
+ goto error;
+
memset(pResHash->treelist->vlist, 0, sizeof(ValueNode));
+ goto done;
+
+error:
+ if (pResHash->treelist->vlist) free(pResHash->treelist->vlist);
+ if (pResHash->treelist) free(pResHash->treelist);
+ if (pResHash) free(pResHash);
+ return NULL;
+
+done:
return pResHash;
}