Skip to content

Commit 599545f

Browse files
committed
Fix another memleak on orig_localenamel
1 parent d7a0a39 commit 599545f

2 files changed

Lines changed: 29 additions & 24 deletions

File tree

cppcheck.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0"?>
22
<def format="2">
33
<define name="VERSION" value="&quot;cppcheck&quot;"/>
4+
<define name="__int64" value="long long"/>
45
</def>

src/framework/mlt_property.c

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@
3737
#include <stdlib.h>
3838
#include <string.h>
3939

40+
// Platforms with native strtod_l support
41+
#if defined(__GLIBC__) || defined(__APPLE__) || (defined(HAVE_STRTOD_L) && !defined(__OpenBSD__))
42+
#define HAVE_LOCALE_STRTOD_L 1
43+
#endif
44+
45+
// Platforms requiring manual locale handling (excluding Windows)
46+
#if !defined(__GLIBC__) && !defined(__APPLE__) && !defined(_WIN32) && !defined(HAVE_STRTOD_L) \
47+
&& !defined(__OpenBSD__)
48+
#define NEED_LOCALE_SAVE_RESTORE 1
49+
#endif
50+
4051
/** Bit pattern used internally to indicated representations available.
4152
*/
4253

@@ -318,8 +329,7 @@ static int time_clock_to_frames(mlt_property self, const char *s, double fps, ml
318329
s = copy;
319330
pos = strrchr(s, ':');
320331

321-
#if !defined(__GLIBC__) && !defined(__APPLE__) && !defined(_WIN32) && !defined(HAVE_STRTOD_L) \
322-
&& !defined(__OpenBSD__)
332+
#ifdef NEED_LOCALE_SAVE_RESTORE
323333
char *orig_localename = NULL;
324334
if (locale) {
325335
// Protect damaging the global locale from a temporary locale on another thread.
@@ -334,7 +344,7 @@ static int time_clock_to_frames(mlt_property self, const char *s, double fps, ml
334344
#endif
335345

336346
if (pos) {
337-
#if defined(__GLIBC__) || defined(__APPLE__) || defined(HAVE_STRTOD_L) && !defined(__OpenBSD__)
347+
#ifdef HAVE_LOCALE_STRTOD_L
338348
if (locale)
339349
seconds = strtod_l(pos + 1, NULL, locale);
340350
else
@@ -350,16 +360,15 @@ static int time_clock_to_frames(mlt_property self, const char *s, double fps, ml
350360
minutes = atoi(s);
351361
}
352362
} else {
353-
#if defined(__GLIBC__) || defined(__APPLE__) || defined(HAVE_STRTOD_L) && !defined(__OpenBSD__)
363+
#ifdef HAVE_LOCALE_STRTOD_L
354364
if (locale)
355365
seconds = strtod_l(s, NULL, locale);
356366
else
357367
#endif
358368
seconds = strtod(s, NULL);
359369
}
360370

361-
#if !defined(__GLIBC__) && !defined(__APPLE__) && !defined(_WIN32) && !defined(HAVE_STRTOD_L) \
362-
&& !defined(__OpenBSD__)
371+
#ifdef NEED_LOCALE_SAVE_RESTORE
363372
if (locale) {
364373
// Restore the current locale
365374
setlocale(LC_NUMERIC, orig_localename);
@@ -513,14 +522,12 @@ int mlt_property_get_int(mlt_property self, double fps, mlt_locale_t locale)
513522
static double mlt_property_atof(mlt_property self, double fps, mlt_locale_t locale)
514523
{
515524
const char *value = self->prop_string;
516-
#if !defined(__GLIBC__) && !defined(__APPLE__) && !defined(_WIN32) && !defined(HAVE_STRTOD_L) \
517-
&& !defined(__OpenBSD__)
525+
#ifdef NEED_LOCALE_SAVE_RESTORE
518526
char *orig_localename = NULL;
519527
#endif
520528

521529
if (fps > 0 && strchr(value, ':')) {
522-
#if !defined(__GLIBC__) && !defined(__APPLE__) && !defined(_WIN32) && !defined(HAVE_STRTOD_L) \
523-
&& !defined(__OpenBSD__)
530+
#ifdef NEED_LOCALE_SAVE_RESTORE
524531
if (locale) {
525532
// Protect damaging the global locale from a temporary locale on another thread.
526533
pthread_mutex_lock(&self->mutex);
@@ -538,8 +545,7 @@ static double mlt_property_atof(mlt_property self, double fps, mlt_locale_t loca
538545
else
539546
result = time_code_to_frames(self, value, fps);
540547

541-
#if !defined(__GLIBC__) && !defined(__APPLE__) && !defined(_WIN32) && !defined(HAVE_STRTOD_L) \
542-
&& !defined(__OpenBSD__)
548+
#ifdef NEED_LOCALE_SAVE_RESTORE
543549
if (locale) {
544550
// Restore the current locale
545551
setlocale(LC_NUMERIC, orig_localename);
@@ -552,7 +558,7 @@ static double mlt_property_atof(mlt_property self, double fps, mlt_locale_t loca
552558
char *end = NULL;
553559
double result;
554560

555-
#if defined(__GLIBC__) || defined(__APPLE__) || defined(HAVE_STRTOD_L) && !defined(__OpenBSD__)
561+
#ifdef HAVE_LOCALE_STRTOD_L
556562
if (locale)
557563
result = strtod_l(value, &end, locale);
558564
else
@@ -573,8 +579,7 @@ static double mlt_property_atof(mlt_property self, double fps, mlt_locale_t loca
573579
if (end && end[0] == '%')
574580
result /= 100.0;
575581

576-
#if !defined(__GLIBC__) && !defined(__APPLE__) && !defined(_WIN32) && !defined(HAVE_STRTOD_L) \
577-
&& !defined(__OpenBSD__)
582+
#ifdef NEED_LOCALE_SAVE_RESTORE
578583
if (locale) {
579584
// Restore the current locale
580585
setlocale(LC_NUMERIC, orig_localename);
@@ -1184,13 +1189,15 @@ int mlt_property_is_numeric(mlt_property self, mlt_locale_t locale)
11841189
// If not already numeric but string is numeric.
11851190
if ((!result && self->types & mlt_prop_string) && self->prop_string) {
11861191
char *p = NULL;
1192+
#ifdef NEED_LOCALE_SAVE_RESTORE
1193+
char *orig_localename = NULL;
1194+
#endif
11871195

1188-
#if defined(__GLIBC__) || defined(__APPLE__) || defined(HAVE_STRTOD_L) && !defined(__OpenBSD__)
1196+
#ifdef HAVE_LOCALE_STRTOD_L
11891197
if (locale)
11901198
strtod_l(self->prop_string, &p, locale);
11911199
else
11921200
#elif !defined(_WIN32)
1193-
char *orig_localename = NULL;
11941201
if (locale) {
11951202
// Protect damaging the global locale from a temporary locale on another thread.
11961203
pthread_mutex_lock(&self->mutex);
@@ -1205,8 +1212,7 @@ int mlt_property_is_numeric(mlt_property self, mlt_locale_t locale)
12051212

12061213
strtod(self->prop_string, &p);
12071214

1208-
#if !defined(__GLIBC__) && !defined(__APPLE__) && !defined(_WIN32) && !defined(HAVE_STRTOD_L) \
1209-
&& !defined(__OpenBSD__)
1215+
#ifdef NEED_LOCALE_SAVE_RESTORE
12101216
if (locale) {
12111217
// Restore the current locale
12121218
setlocale(LC_NUMERIC, orig_localename);
@@ -1921,8 +1927,7 @@ mlt_rect mlt_property_get_rect(mlt_property self, mlt_locale_t locale)
19211927
char *p = NULL;
19221928
int count = 0;
19231929

1924-
#if !defined(__GLIBC__) && !defined(__APPLE__) && !defined(_WIN32) && !defined(HAVE_STRTOD_L) \
1925-
&& !defined(__OpenBSD__)
1930+
#ifdef NEED_LOCALE_SAVE_RESTORE
19261931
char *orig_localename = NULL;
19271932
if (locale) {
19281933
// Protect damaging the global locale from a temporary locale on another thread.
@@ -1938,7 +1943,7 @@ mlt_rect mlt_property_get_rect(mlt_property self, mlt_locale_t locale)
19381943

19391944
while (*value) {
19401945
double temp;
1941-
#if defined(__GLIBC__) || defined(__APPLE__) || defined(HAVE_STRTOD_L) && !defined(__OpenBSD__)
1946+
#ifdef HAVE_LOCALE_STRTOD_L
19421947
if (locale)
19431948
temp = strtod_l(value, &p, locale);
19441949
else
@@ -1979,8 +1984,7 @@ mlt_rect mlt_property_get_rect(mlt_property self, mlt_locale_t locale)
19791984
count++;
19801985
}
19811986

1982-
#if !defined(__GLIBC__) && !defined(__APPLE__) && !defined(_WIN32) && !defined(HAVE_STRTOD_L) \
1983-
&& !defined(__OpenBSD__)
1987+
#ifdef NEED_LOCALE_SAVE_RESTORE
19841988
if (locale) {
19851989
// Restore the current locale
19861990
setlocale(LC_NUMERIC, orig_localename);

0 commit comments

Comments
 (0)