Browse Source

Bug 616500 - fix coverify Defect Type: Resource leaks issues CID 12094 - 12136

https://bugzilla.redhat.com/show_bug.cgi?id=616500
Resolves: bug 616500
Bug description: fix coverify Defect Type: Resource leaks issues CID 12136
description: Fixed resource leaks in XP_MakeStringProperties().
Endi S. Dewata 15 years ago
parent
commit
ec118b1ed6
1 changed files with 16 additions and 5 deletions
  1. 16 5
      lib/libsi18n/makstrdb.c

+ 16 - 5
lib/libsi18n/makstrdb.c

@@ -160,13 +160,21 @@ XP_MakeStringProperties(void)
     int j;
     char* LibraryName;
     RESOURCE_TABLE* table;
-    FILE *hresfile;
+    FILE *hresfile = NULL;
     char buffer[2000];
     char *src, *dest;
-    char *dbfile;
+    char *dbfile = NULL;
+    int rc = 0;
   
     /* Creating database */
     dbfile = (char *) malloc (strlen(DATABASE_NAME) + 20);
+
+    if (dbfile==NULL) {
+        printf("Out of memory\n");
+        rc = 1;
+        goto done;
+    }
+
     strcpy(dbfile, DATABASE_NAME);
     strcat(dbfile, ".properties");
 
@@ -174,7 +182,8 @@ XP_MakeStringProperties(void)
 
     if (hresfile==NULL) {
         printf("Error creating properties file %s\n",DATABASE_NAME);
-        return 1;
+        rc = 1;
+        goto done;
     }
  
     j = 0;
@@ -213,8 +222,10 @@ XP_MakeStringProperties(void)
         }
     }
   
-    fclose(hresfile);
-    return 0;
+done:
+    if (hresfile) fclose(hresfile);
+    if (dbfile) free(dbfile);
+    return rc;
 }