7189533: GetJavaProperties should free temporary file if subsequent allocations fails
authorandrew
Wed, 08 Aug 2012 12:37:02 +0100
changeset 13414 1e161ce0b69e
parent 13413 1ed9a01478b4
child 13415 0430f69eed3b
7189533: GetJavaProperties should free temporary file if subsequent allocations fails Summary: Add missing calls to free Reviewed-by: alanb, dholmes, sherman
jdk/src/solaris/native/java/lang/java_props_md.c
--- a/jdk/src/solaris/native/java/lang/java_props_md.c	Tue Aug 07 20:23:41 2012 -0700
+++ b/jdk/src/solaris/native/java/lang/java_props_md.c	Wed Aug 08 12:37:02 2012 +0100
@@ -140,7 +140,7 @@
     char *temp = NULL;
     char *language = NULL, *country = NULL, *variant = NULL,
          *encoding = NULL;
-    char *p, *encoding_variant;
+    char *p, *encoding_variant, *old_temp, *old_ev;
     char *lc;
 
     /* Query the locale set for the category */
@@ -219,6 +219,7 @@
 
     encoding_variant = malloc(strlen(temp)+1);
     if (encoding_variant == NULL) {
+        free(temp);
         JNU_ThrowOutOfMemoryError(env, NULL);
         return 0;
     }
@@ -234,14 +235,20 @@
     }
 
     if (mapLookup(locale_aliases, temp, &p)) {
+        old_temp = temp;
         temp = realloc(temp, strlen(p)+1);
         if (temp == NULL) {
+            free(old_temp);
+            free(encoding_variant);
             JNU_ThrowOutOfMemoryError(env, NULL);
             return 0;
         }
         strcpy(temp, p);
+        old_ev = encoding_variant;
         encoding_variant = realloc(encoding_variant, strlen(temp)+1);
         if (encoding_variant == NULL) {
+            free(old_ev);
+            free(temp);
             JNU_ThrowOutOfMemoryError(env, NULL);
             return 0;
         }