java_props_macosx.c : CFLocaleCopyCurrent() needs CFRelease ?
naoto.sato at oracle.com
naoto.sato at oracle.com
Mon Jul 22 19:56:50 UTC 2019
Hi Matthias,
Thanks for catching them. Yes, I believe they should be released
appropriately.
Naoto
On 7/22/19 4:01 AM, Baesken, Matthias wrote:
> Hello , maybe someone with more OSX dev knowledge could comment on this .
> If I understand it correctly , the OSX Core Foundation Ownership Policy :
>
> https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-103029
>
> says that "Object-duplication functions that have "Copy" embedded in the name." (like CFLocaleCopyCurrent ) need to
> relinquish ownership (using CFRelease<https://developer.apple.com/documentation/corefoundation/1521153-cfrelease>) when you have finished with it.
>
> Should we better add then CFRelease to the 2 CFLocaleCopyCurrent usages in src/java.base/macosx/native/libjava/java_props_macosx.c (coding below) ?
> Or do I miss something ?
>
> Thanks , Matthias
>
>
>
> --- a/src/java.base/macosx/native/libjava/java_props_macosx.c Fri Jul 19 10:18:48 2019 +0200
> +++ b/src/java.base/macosx/native/libjava/java_props_macosx.c Mon Jul 22 12:47:21 2019 +0200
> @@ -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,18 @@
> default:
> {
> - if (!CFStringGetCString(CFLocaleGetIdentifier(CFLocaleCopyCurrent()),
> - localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding())) {
> + CFLocaleRef cflocale = CFLocaleCopyCurrent();
> + if (cflocale != NULL) {
> + if (!CFStringGetCString(CFLocaleGetIdentifier(cflocale),
> + localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding())) {
> + return NULL;
> + }
> +
> + retVal = localeString;
> + CFRelease(cflocale);
> + } else {
> return NULL;
> }
> -
> - retVal = localeString;
> }
> break;
> }
>
>
More information about the core-libs-dev
mailing list