8211149: fix potential memleak in getJavaIDFromLangID after failing SetupI18nProps call [windows]
Reviewed-by: naoto, lucy
--- 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;
}