diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2006-07-16 02:15:27 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2006-07-16 02:15:27 (GMT) |
commit | 5eaf772980a5013c89a9d3814991ff3244ed58f1 (patch) | |
tree | 277a10937019dd01b3bd5d5856bc698f31caf9d0 /Modules | |
parent | 109f91414fe32e7d7dacbd8050c0b9992d0531db (diff) | |
download | cpython-5eaf772980a5013c89a9d3814991ff3244ed58f1.zip cpython-5eaf772980a5013c89a9d3814991ff3244ed58f1.tar.gz cpython-5eaf772980a5013c89a9d3814991ff3244ed58f1.tar.bz2 |
Fix memory leaks in some conditions.
Reported by Klocwork #152.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/readline.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/Modules/readline.c b/Modules/readline.c index 8fda228..92f2d1f 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -20,6 +20,12 @@ #include <locale.h> #endif +#ifdef SAVE_LOCALE +# define RESTORE_LOCALE(sl) { setlocale(LC_CTYPE, sl); free(sl); } +#else +# define RESTORE_LOCALE(sl) +#endif + /* GNU readline definitions */ #undef HAVE_CONFIG_H /* Else readline/chardefs.h includes strings.h */ #include <readline/readline.h> @@ -723,10 +729,7 @@ setup_readline(void) */ rl_initialize(); -#ifdef SAVE_LOCALE - setlocale(LC_CTYPE, saved_locale); /* Restore locale */ - free(saved_locale); -#endif + RESTORE_LOCALE(saved_locale) } /* Wrapper around GNU readline that handles signals differently. */ @@ -864,7 +867,8 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt) p = readline_until_enter_or_signal(prompt, &signal); /* we got an interrupt signal */ - if(signal) { + if (signal) { + RESTORE_LOCALE(saved_locale) return NULL; } @@ -873,6 +877,7 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt) p = PyMem_Malloc(1); if (p != NULL) *p = '\0'; + RESTORE_LOCALE(saved_locale) return p; } @@ -905,10 +910,7 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt) p[n+1] = '\0'; } free(q); -#ifdef SAVE_LOCALE - setlocale(LC_CTYPE, saved_locale); /* Restore locale */ - free(saved_locale); -#endif + RESTORE_LOCALE(saved_locale) return p; } |