[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
another memory leak, with patch
From: |
Ben Pfaff |
Subject: |
another memory leak, with patch |
Date: |
Mon, 24 Nov 2008 22:12:57 -0800 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) |
valgrind reports:
==3634== 194 (102 direct, 92 indirect) bytes in 4 blocks are definitely
lost in loss record 12 of 15
==3634== at 0x4022AB8: malloc (vg_replace_malloc.c:207)
==3634== by 0x40E37C1: xmalloc (xmalloc.c:49)
==3634== by 0x414FDA1: get_system_decimal (i18n.c:237)
==3634== by 0x413D944: settings_init (settings.c:153)
==3634== by 0x804A808: main (main.c:109)
Proposed fix below. Comments?
commit 17aed102d2f038e56b33eb0124652e15a21631e6
Author: Ben Pfaff <address@hidden>
Date: Mon Nov 24 22:12:01 2008 -0800
Fix memory leak in get_system_decimal().
diff --git a/src/libpspp/i18n.c b/src/libpspp/i18n.c
index bda2676..db85121 100644
--- a/src/libpspp/i18n.c
+++ b/src/libpspp/i18n.c
@@ -225,24 +225,24 @@ i18n_done (void)
char
get_system_decimal (void)
{
- char *radix_char = NULL;
+ char radix_char;
char *ol = setlocale (LC_NUMERIC, NULL);
setlocale (LC_NUMERIC, "");
#if HAVE_NL_LANGINFO
- radix_char = nl_langinfo (RADIXCHAR);
+ radix_char = nl_langinfo (RADIXCHAR)[0];
#else
{
- char *buf = xmalloc (10);
- snprintf (buf, 10, "%f", 2.5);
- radix_char = &buf[1];
+ char buf[10];
+ snprintf (buf, sizeof buf, "%f", 2.5);
+ radix_char = buf[1];
}
#endif
/* We MUST leave LC_NUMERIC untouched, since it would
otherwise interfere with data_{in,out} */
setlocale (LC_NUMERIC, ol);
- return *radix_char;
+ return radix_char;
}
--
Ben Pfaff
http://benpfaff.org
- another memory leak, with patch,
Ben Pfaff <=