Commit 01bc17a2 authored by Neal Norwitz's avatar Neal Norwitz

Fix memory leaks in some conditions.

Reported by Klocwork #152.
parent 14d70610
...@@ -20,6 +20,12 @@ ...@@ -20,6 +20,12 @@
#include <locale.h> #include <locale.h>
#endif #endif
#ifdef SAVE_LOCALE
# define RESTORE_LOCALE(sl) { setlocale(LC_CTYPE, sl); free(sl); }
#else
# define RESTORE_LOCALE(sl)
#endif
/* GNU readline definitions */ /* GNU readline definitions */
#undef HAVE_CONFIG_H /* Else readline/chardefs.h includes strings.h */ #undef HAVE_CONFIG_H /* Else readline/chardefs.h includes strings.h */
#include <readline/readline.h> #include <readline/readline.h>
...@@ -723,10 +729,7 @@ setup_readline(void) ...@@ -723,10 +729,7 @@ setup_readline(void)
*/ */
rl_initialize(); rl_initialize();
#ifdef SAVE_LOCALE RESTORE_LOCALE(saved_locale)
setlocale(LC_CTYPE, saved_locale); /* Restore locale */
free(saved_locale);
#endif
} }
/* Wrapper around GNU readline that handles signals differently. */ /* Wrapper around GNU readline that handles signals differently. */
...@@ -864,7 +867,8 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt) ...@@ -864,7 +867,8 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt)
p = readline_until_enter_or_signal(prompt, &signal); p = readline_until_enter_or_signal(prompt, &signal);
/* we got an interrupt signal */ /* we got an interrupt signal */
if(signal) { if (signal) {
RESTORE_LOCALE(saved_locale)
return NULL; return NULL;
} }
...@@ -873,6 +877,7 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt) ...@@ -873,6 +877,7 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt)
p = PyMem_Malloc(1); p = PyMem_Malloc(1);
if (p != NULL) if (p != NULL)
*p = '\0'; *p = '\0';
RESTORE_LOCALE(saved_locale)
return p; return p;
} }
...@@ -905,10 +910,7 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt) ...@@ -905,10 +910,7 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt)
p[n+1] = '\0'; p[n+1] = '\0';
} }
free(q); free(q);
#ifdef SAVE_LOCALE RESTORE_LOCALE(saved_locale)
setlocale(LC_CTYPE, saved_locale); /* Restore locale */
free(saved_locale);
#endif
return p; return p;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment