changeset 55812:de62b363bbe6

8228501: java_props_macosx.c - provide missing CFRelease for CFLocaleCopyCurrent Reviewed-by: naoto
author mbaesken
date Wed, 24 Jul 2019 09:28:48 +0200
parents a2912ba36422
children 51286afcbf49
files src/java.base/macosx/native/libjava/java_props_macosx.c
diffstat 1 files changed, 26 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/macosx/native/libjava/java_props_macosx.c	Mon Jul 22 16:32:58 2019 -0400
+++ b/src/java.base/macosx/native/libjava/java_props_macosx.c	Wed Jul 24 09:28:48 2019 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -91,18 +91,22 @@
 
             if (hyphenPos == NULL || // languageString contains ISO639 only, e.g., "en"
                 languageString + langStrLen - hyphenPos == 5) { // ISO639-ScriptCode, e.g., "en-Latn"
-                CFStringGetCString(CFLocaleGetIdentifier(CFLocaleCopyCurrent()),
-                               localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding());
-                char *underscorePos = strrchr(localeString, '_');
-                char *region = NULL;
+                CFLocaleRef cflocale = CFLocaleCopyCurrent();
+                if (cflocale != NULL) {
+                    CFStringGetCString(CFLocaleGetIdentifier(cflocale),
+                                   localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding());
+                    char *underscorePos = strrchr(localeString, '_');
+                    char *region = NULL;
 
-                if (underscorePos != NULL) {
-                    region = underscorePos + 1;
-                }
+                    if (underscorePos != NULL) {
+                        region = underscorePos + 1;
+                    }
 
-                if (region != NULL) {
-                    strcat(languageString, "-");
-                    strcat(languageString, region);
+                    if (region != NULL) {
+                        strcat(languageString, "-");
+                        strcat(languageString, region);
+                    }
+                    CFRelease(cflocale);
                 }
             }
 
@@ -112,12 +116,19 @@
 
     default:
         {
-            if (!CFStringGetCString(CFLocaleGetIdentifier(CFLocaleCopyCurrent()),
-                                    localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding())) {
+            CFLocaleRef cflocale = CFLocaleCopyCurrent();
+            if (cflocale != NULL) {
+                if (!CFStringGetCString(CFLocaleGetIdentifier(cflocale),
+                                        localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding())) {
+                    CFRelease(cflocale);
+                    return NULL;
+                }
+
+                retVal = localeString;
+                CFRelease(cflocale);
+            } else {
                 return NULL;
             }
-
-            retVal = localeString;
         }
         break;
     }