Преглед на файлове

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().
Endi S. Dewata преди 15 години
родител
ревизия
e63bd50a2e
променени са 1 файла, в които са добавени 18 реда и са изтрити 3 реда
  1. 18 3
      lib/libsi18n/reshash.c

+ 18 - 3
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;
 }