[Python-checkins] r50677 - python/trunk/Modules/readline.c
neal.norwitz
python-checkins at python.org
Sun Jul 16 04:15:28 CEST 2006
Author: neal.norwitz
Date: Sun Jul 16 04:15:27 2006
New Revision: 50677
Modified:
python/trunk/Modules/readline.c
Log:
Fix memory leaks in some conditions.
Reported by Klocwork #152.
Modified: python/trunk/Modules/readline.c
==============================================================================
--- python/trunk/Modules/readline.c (original)
+++ python/trunk/Modules/readline.c Sun Jul 16 04:15:27 2006
@@ -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 @@
*/
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 @@
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 @@
p = PyMem_Malloc(1);
if (p != NULL)
*p = '\0';
+ RESTORE_LOCALE(saved_locale)
return p;
}
@@ -905,10 +910,7 @@
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;
}
More information about the Python-checkins
mailing list