From: Eric Hawicz Date: Sun, 30 Jul 2023 17:38:15 +0000 (-0400) Subject: Issue #668: add the option to specify "cmake -DUSELOCALE_NEEDS_FREELOCALE=1" to work... X-Git-Tag: json-c-0.17-20230812~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=71d845e819d5efb0265905798e8a2b3ae0958515;p=thirdparty%2Fjson-c.git Issue #668: add the option to specify "cmake -DUSELOCALE_NEEDS_FREELOCALE=1" to work around a bug in older versions of FreeBSD (<12.4). --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d64a6bd..ada8b0c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,6 +89,7 @@ option(ENABLE_THREADING "Enable partial threading support." option(OVERRIDE_GET_RANDOM_SEED "Override json_c_get_random_seed() with custom code." OFF) option(DISABLE_EXTRA_LIBS "Avoid linking against extra libraries, such as libbsd." OFF) option(DISABLE_JSON_POINTER "Disable JSON pointer (RFC6901) support." OFF) +option(NEWLOCALE_NEEDS_FREELOCALE "Work around newlocale bugs in old FreeBSD by calling freelocale" OFF) if (UNIX OR MINGW OR CYGWIN) diff --git a/cmake/config.h.in b/cmake/config.h.in index be0202ab..1e6359d0 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -137,6 +137,9 @@ /* Define to 1 if you have the `uselocale' function. */ #cmakedefine HAVE_USELOCALE +/* Define to 1 if newlocale() needs freelocale() called on it's `base` argument */ +#cmakedefine NEWLOCALE_NEEDS_FREELOCALE + /* Define to 1 if you have the `vasprintf' function. */ #cmakedefine HAVE_VASPRINTF diff --git a/json_tokener.c b/json_tokener.c index 25f41dcb..9403f850 100644 --- a/json_tokener.c +++ b/json_tokener.c @@ -344,6 +344,11 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char * freelocale(duploc); return NULL; } +#ifdef NEWLOCALE_NEEDS_FREELOCALE + // Older versions of FreeBSD (<12.4) don't free the locale + // passed to newlocale(), so do it here + freelocale(duploc); +#endif uselocale(newloc); } #elif defined(HAVE_SETLOCALE)