[Python-checkins] r52104 - python/branches/release24-maint/Modules/readline.c

andrew.kuchling python-checkins at python.org
Tue Oct 3 20:29:35 CEST 2006


Author: andrew.kuchling
Date: Tue Oct  3 20:29:35 2006
New Revision: 52104

Modified:
   python/branches/release24-maint/Modules/readline.c
Log:
[Backport r50677 | neal.norwitz]

Fix memory leaks in some conditions.

Reported by Klocwork #152.


Modified: python/branches/release24-maint/Modules/readline.c
==============================================================================
--- python/branches/release24-maint/Modules/readline.c	(original)
+++ python/branches/release24-maint/Modules/readline.c	Tue Oct  3 20:29:35 2006
@@ -22,6 +22,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>
@@ -725,10 +731,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. */
@@ -866,7 +869,8 @@
 	p = readline_until_enter_or_signal(prompt, &signal);
 	
 	/* we got an interrupt signal */
-	if(signal) {
+	if (signal) {
+		RESTORE_LOCALE(saved_locale)
 		return NULL;
 	}
 
@@ -875,6 +879,7 @@
 		p = PyMem_Malloc(1);
 		if (p != NULL)
 			*p = '\0';
+		RESTORE_LOCALE(saved_locale)
 		return p;
 	}
 
@@ -907,10 +912,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