Mac: fix double free

Had wrongfully assumed CFStringRef's were reference counted
objects that needed to be CFRelease()'d when we no longer
needed them.

However according to the CFArrayGetValueAtIndex() API docs
( https://developer.apple.com/documentation/corefoundation/1388767-cfarraygetvalueatindex?language=objc )
it follows "get rule" for memory ownership, meaning it is not
ours to release.

Only prefLangs returned by CFLocaleCopyPreferredLanguages()
need to be CFRelease()'d as that does follow "create rule"

Ref #202 (Crash on Mac OS Big Sur)
This commit is contained in:
Floris Bos 2021-04-05 16:32:46 +02:00
parent a82fe15d54
commit 1aaf22d7ab
2 changed files with 2 additions and 3 deletions

View file

@ -9,8 +9,8 @@ endif()
project(rpi-imager LANGUAGES CXX C)
set(IMAGER_VERSION_MAJOR 1)
set(IMAGER_VERSION_MINOR 6)
set(IMAGER_VERSION_STR "${IMAGER_VERSION_MAJOR}.${IMAGER_VERSION_MINOR}.1")
set(IMAGER_VERSION_CSV "${IMAGER_VERSION_MAJOR},${IMAGER_VERSION_MINOR},1,0")
set(IMAGER_VERSION_STR "${IMAGER_VERSION_MAJOR}.${IMAGER_VERSION_MINOR}.2")
set(IMAGER_VERSION_CSV "${IMAGER_VERSION_MAJOR},${IMAGER_VERSION_MINOR},2,0")
add_definitions(-DIMAGER_VERSION_STR="${IMAGER_VERSION_STR}")
add_definitions(-DIMAGER_VERSION_CSV=${IMAGER_VERSION_CSV})

View file

@ -185,7 +185,6 @@ int main(int argc, char *argv[])
char buf[32] = {0};
CFStringRef strRef = (CFStringRef) CFArrayGetValueAtIndex(prefLangs, 0);
CFStringGetCString(strRef, buf, sizeof(buf), kCFStringEncodingUTF8);
CFRelease(strRef);
langcode = buf;
langcode.replace('-', '_');
qDebug() << "OSX most preferred language:" << langcode;