8211149: fix potential memleak in getJavaIDFromLangID after failing SetupI18nProps call [windows]
authormbaesken
Thu, 27 Sep 2018 15:37:55 +0200
changeset 51943 5e9c922eafbc
parent 51942 1d12935177ed
child 51944 28085dba5d9a
8211149: fix potential memleak in getJavaIDFromLangID after failing SetupI18nProps call [windows] Reviewed-by: naoto, lucy
src/java.base/windows/native/libjava/java_props_md.c
--- a/src/java.base/windows/native/libjava/java_props_md.c	Fri Sep 28 09:20:46 2018 +0200
+++ b/src/java.base/windows/native/libjava/java_props_md.c	Thu Sep 27 15:37:55 2018 +0200
@@ -170,6 +170,10 @@
         return NULL;
     }
 
+    for (index = 0; index < 5; index++) {
+        elems[index] = NULL;
+    }
+
     if (SetupI18nProps(MAKELCID(langID, SORT_DEFAULT),
                    &(elems[0]), &(elems[1]), &(elems[2]), &(elems[3]), &(elems[4]))) {
 
@@ -183,15 +187,17 @@
                 strcat(ret, elems[index]);
             }
         }
-
-        for (index = 0; index < 5; index++) {
-            free(elems[index]);
-        }
     } else {
         free(ret);
         ret = NULL;
     }
 
+    for (index = 0; index < 5; index++) {
+        if (elems[index] != NULL) {
+            free(elems[index]);
+        }
+    }
+
     return ret;
 }