From: "Miguel Ángel Arruga Vivas" <rosen644835@gmail.com>
To: guile-devel@gnu.org
Subject: [WIP: PATCH 1/2] memory leak
Date: Tue, 13 Oct 2020 21:14:18 +0200 [thread overview]
Message-ID: <87a6wq0whh.fsf@gmail.com> (raw)
In-Reply-To: <87h7qy0wlc.fsf@gmail.com> ("Miguel Ángel Arruga Vivas"'s message of "Tue, 13 Oct 2020 21:11:59 +0200")
[-- Attachment #1.1: Type: text/plain, Size: 44 bytes --]
Here it's the patch about the memory leak.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-mml.patch --]
[-- Type: text/x-patch, Size: 1697 bytes --]
From 888f31dfedc1292cff9fce2d2ef20f986c2fb669 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
<rosen644835@gmail.com>
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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 658 bytes --]
next prev parent reply other threads:[~2020-10-13 19:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-13 19:11 [WIP: PATCH 0/2] memory leak + uselocale Miguel Ángel Arruga Vivas
2020-10-13 19:14 ` Miguel Ángel Arruga Vivas [this message]
2020-10-13 19:15 ` [WIP: PATCH 2/2] uselocale Miguel Ángel Arruga Vivas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87a6wq0whh.fsf@gmail.com \
--to=rosen644835@gmail.com \
--cc=guile-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).