Here it's the patch about the memory leak.
From 888f31dfedc1292cff9fce2d2ef20f986c2fb669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?= <[email protected]> Date: Mon, 12 Oct 2020 13:25:25 +0200 Subject: [PATCH 1/2] Fix memory leak after an error.
* libguile/i18n.c (get_current_locale_name): Use the intermediate
variable val to cleanup the copied strings in case of error.
---
libguile/i18n.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/libguile/i18n.c b/libguile/i18n.c
index fc47fdfe5..7b80e7427 100644
--- a/libguile/i18n.c
+++ b/libguile/i18n.c
@@ -311,7 +311,10 @@ typedef struct
static int
get_current_locale_settings (scm_t_locale_settings *settings)
{
+ int error;
const char *locale_name;
+ scm_t_locale_settings val;
+ memset (&val, 0, sizeof (val));
#define SCM_DEFINE_LOCALE_CATEGORY(_name) \
{ \
@@ -319,21 +322,26 @@ get_current_locale_settings (scm_t_locale_settings *settings)
if (locale_name == NULL) \
goto handle_error; \
\
- settings-> _name = strdup (locale_name); \
- if (settings-> _name == NULL) \
+ val. _name = strdup (locale_name); \
+ if (val. _name == NULL) \
goto handle_oom; \
}
#include "locale-categories.h"
#undef SCM_DEFINE_LOCALE_CATEGORY
+ memcpy(settings, &val, sizeof (val));
return 0;
handle_error:
- return EINVAL;
+ error = EINVAL;
+ goto cleanup;
handle_oom:
- return ENOMEM;
+ error = ENOMEM;
+ cleanup:
+ free_locale_settings(&val);
+ return error;
}
/* Restore locale settings SETTINGS. On success, return zero. */
--
2.28.0
signature.asc
Description: PGP signature
