From 75f49aaec509d8feb2a272a19db5d8cfa40b0bb1 Mon Sep 17 00:00:00 2001 From: Richard Cohen Date: Thu, 20 Jul 2023 15:46:17 +0100 Subject: [PATCH] Valgrind: fix "definitely lost" memory in (gnc-mktime) - test-invoice-report-builtin-default ==158291== 6 bytes in 1 blocks are definitely lost in loss record 18 of 824 ==158291== at 0x4848C63: realloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==158291== by 0x4A91473: scm_realloc (in /usr/lib/x86_64-linux-gnu/libguile-3.0.so.1.5.0) ==158291== by 0x4AFF26B: scm_to_stringn (in /usr/lib/x86_64-linux-gnu/libguile-3.0.so.1.5.0) ==158291== by 0x4CB473D: _wrap_gnc_mktime(scm_unused_struct*) (swig-engine.cpp:38703) ... --- common/base-typemaps.i | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/common/base-typemaps.i b/common/base-typemaps.i index fbae4c3e98..ebd1355d4d 100644 --- a/common/base-typemaps.i +++ b/common/base-typemaps.i @@ -69,7 +69,7 @@ typedef char gchar; %typemap(in) time64 * (time64 t) "t = scm_to_int64($input); $1 = &t;" %typemap(out) time64 * " $result = ($1) ? scm_from_int64(*($1)) : SCM_BOOL_F; " -%typemap(in) struct tm * (struct tm t) { +%typemap(in) struct tm * (struct tm t, char *tzone) { SCM tm = $input; t.tm_sec = scm_to_int(SCM_SIMPLE_VECTOR_REF(tm, 0)); t.tm_min = scm_to_int(SCM_SIMPLE_VECTOR_REF(tm, 1)); @@ -83,10 +83,16 @@ typedef char gchar; %#ifdef HAVE_STRUCT_TM_GMTOFF t.tm_gmtoff = scm_to_int(SCM_SIMPLE_VECTOR_REF(tm, 9)); SCM zone = SCM_SIMPLE_VECTOR_REF(tm, 10); - t.tm_zone = SCM_UNBNDP(zone) ? NULL : scm_to_locale_string(zone); + tzone = SCM_UNBNDP(zone) ? NULL : scm_to_locale_string(zone); + t.tm_zone = tzone; %#endif $1 = &t; } +%typemap(freearg) struct tm * { +%#ifdef HAVE_STRUCT_TM_GMTOFF + free(tzone$argnum); +%#endif +} %typemap(out) struct tm * { SCM tm = scm_c_make_vector(11, SCM_UNDEFINED);