From 1aaf22d7aba996d150d79971cc01eac3284ed1ea Mon Sep 17 00:00:00 2001 From: Floris Bos Date: Mon, 5 Apr 2021 16:32:46 +0200 Subject: [PATCH] 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) --- CMakeLists.txt | 4 ++-- main.cpp | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b4f9cde..93e9278 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/main.cpp b/main.cpp index cd91f66..2172a1c 100644 --- a/main.cpp +++ b/main.cpp @@ -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;