Skip to content

Commit 94099ce

Browse files
author
Daniel Shelepanov
committed
[PBCKP-216] correct resources freeing
1 parent d8980be commit 94099ce

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

src/pg_probackup.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ main(int argc, char *argv[])
312312
PROGRAM_FULL_PATH = palloc0(MAXPGPATH);
313313

314314
// Setting C locale for numeric values in order to impose dot-based floating-point representation
315+
memorize_environment_locale();
315316
setlocale(LC_NUMERIC, "C");
316317

317318
/* Get current time */
@@ -1027,6 +1028,8 @@ main(int argc, char *argv[])
10271028
break;
10281029
}
10291030

1031+
free_environment_locale();
1032+
10301033
return 0;
10311034
}
10321035

src/pg_probackup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,8 @@ extern InstanceConfig *readInstanceConfigFile(InstanceState *instanceState);
905905
/* in show.c */
906906
extern int do_show(CatalogState *catalogState, InstanceState *instanceState,
907907
time_t requested_backup_id, bool show_archive);
908+
extern void memorize_environment_locale(void);
909+
extern void free_environment_locale(void);
908910

909911
/* in delete.c */
910912
extern void do_delete(InstanceState *instanceState, time_t backup_id);

src/show.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,39 @@ static PQExpBufferData show_buf;
7272
static bool first_instance = true;
7373
static int32 json_level = 0;
7474

75+
static const char* lc_env_locale;
7576
typedef enum {
76-
LOCALE_PROBACKUP,
77+
LOCALE_OUTPUT,
7778
LOCALE_ENV
7879
} output_numeric_locale;
7980

81+
#ifdef HAVE_USELOCALE
82+
static locale_t env_locale, out_locale;
83+
#endif
84+
void memorize_environment_locale() {
85+
lc_env_locale = (const char *)getenv("LC_NUMERIC");
86+
lc_env_locale = lc_env_locale != NULL ? lc_env_locale : "C";
87+
#ifdef HAVE_USELOCALE
88+
env_locale = newlocale(LC_NUMERIC_MASK, lc_env_locale, (locale_t)0);
89+
out_locale = newlocale(LC_NUMERIC_MASK, "C", (locale_t)0);
90+
#endif
91+
}
92+
93+
void free_environment_locale() {
94+
#ifdef HAVE_USELOCALE
95+
freelocale(env_locale);
96+
freelocale(out_locale);
97+
#endif
98+
}
99+
80100
static void set_output_numeric_locale(output_numeric_locale loc) {
81-
const char *l = loc == LOCALE_PROBACKUP ? "C" :
82-
getenv("LC_NUMERIC") != NULL ? (const char *)getenv("LC_NUMERIC") : "C";
83-
// Setting environment-specified locale
84101
#ifdef HAVE_USELOCALE
85-
uselocale(newlocale(LC_NUMERIC_MASK, l, (locale_t) 0));
102+
uselocale(loc == LOCALE_OUTPUT ? out_locale : env_locale);
86103
#else
87104
#ifdef HAVE__CONFIGTHREADLOCALE
88105
_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
89106
#endif
90-
setlocale(LC_NUMERIC, l);
107+
setlocale(LC_NUMERIC, loc == LOCALE_OUTPUT ? lc_env_locale : "C");
91108
#endif
92109
}
93110

@@ -131,7 +148,7 @@ do_show(CatalogState *catalogState, InstanceState *instanceState,
131148
show_instance(instanceState, INVALID_BACKUP_ID, true);
132149
}
133150
show_instance_end();
134-
set_output_numeric_locale(LOCALE_PROBACKUP);
151+
set_output_numeric_locale(LOCALE_OUTPUT);
135152

136153
return 0;
137154
}
@@ -150,7 +167,7 @@ do_show(CatalogState *catalogState, InstanceState *instanceState,
150167
show_instance(instanceState, requested_backup_id, false);
151168

152169
show_instance_end();
153-
set_output_numeric_locale(LOCALE_PROBACKUP);
170+
set_output_numeric_locale(LOCALE_OUTPUT);
154171

155172
return 0;
156173
}
@@ -164,7 +181,7 @@ do_show(CatalogState *catalogState, InstanceState *instanceState,
164181
else
165182
show_backup(instanceState, requested_backup_id);
166183

167-
set_output_numeric_locale(LOCALE_PROBACKUP);
184+
set_output_numeric_locale(LOCALE_OUTPUT);
168185
return 0;
169186
}
170187
}

0 commit comments

Comments
 (0)