changeset 51943:5e9c922eafbc

8211149: fix potential memleak in getJavaIDFromLangID after failing SetupI18nProps call [windows] Reviewed-by: naoto, lucy
author mbaesken
date Thu, 27 Sep 2018 15:37:55 +0200
parents 1d12935177ed
children 28085dba5d9a
files src/java.base/windows/native/libjava/java_props_md.c
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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;
 }