From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?Miguel_=C3=81ngel_Arruga_Vivas?= Newsgroups: gmane.lisp.guile.devel Subject: [WIP: PATCH 1/2] memory leak Date: Tue, 13 Oct 2020 21:14:18 +0200 Message-ID: <87a6wq0whh.fsf@gmail.com> References: <87h7qy0wlc.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3366"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Tue Oct 13 21:20:00 2020 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSPq4-0000kp-Kh for guile-devel@m.gmane-mx.org; Tue, 13 Oct 2020 21:20:00 +0200 Original-Received: from localhost ([::1]:33254 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kSPq3-00068a-NO for guile-devel@m.gmane-mx.org; Tue, 13 Oct 2020 15:19:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35522) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kSPlf-0002PD-Fe for guile-devel@gnu.org; Tue, 13 Oct 2020 15:15:27 -0400 Original-Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:53558) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kSPld-00070d-OC for guile-devel@gnu.org; Tue, 13 Oct 2020 15:15:27 -0400 Original-Received: by mail-wm1-x332.google.com with SMTP id f21so741453wml.3 for ; Tue, 13 Oct 2020 12:15:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:references:date:in-reply-to:message-id:user-agent :mime-version; bh=0SYcVH9cmNgsRqnStrNuJg8PfY6iTtwie3ihv9GspHo=; b=rAKd4SZDZ2FSJYjp5fXtTWp9aFM+QjLm7S8EnHeASd5nFiFYOrl0NH7/G3U3cihP9Q 6eKILa9sV9IoZyRG1ap0E1eVFP6rZ1RggDNyHGmaIB/5ufj1wUh0vEf3eAO1ABEnGyKm VSFtc6KJD0AsrN8KQ6/dUaSJVJxnHnjqq46IkZmq0ZzIMvgMUt1di8YPVskDhZpVHjd1 VOAcgSOS5yq8/7G3a8/RnZQwy3ZT5zRPNkdehUTKtUxc4kOeVPEXUfNo2VoduxDwea8I LyDXynWBi+sscTOUed8+WxbAhiNj+FF5prdWepzwUHDagatKf70tftHX+2TSHEzsDeUG 9iYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=0SYcVH9cmNgsRqnStrNuJg8PfY6iTtwie3ihv9GspHo=; b=knQ33Q8eTTiAHY3L66/v1Kd+mh+cII5CGmTSZoKw2i5B8V0VBK00JZVY+I7wv8uA+L aolkM4azwgzUT5Bn+nn79UDbdqAWwhV/rLje9kHjITyhRXU2ZDa2zHiJZs3hOdUb3nIP Ik6+d8PfOClFagGQkDQF6QgAeRzeqSPfPi6o5RbJpqa2ItqqaxbjEuGOHqfKXxVC7me5 cqkQby30WyvQxcw3BkBeKq0vmDXnRrFWxSM+VZJXciRmdJwwhMzHHOVvmgG3Ijg9UxXk WBELzTCtVWKwyEZXMLJxYqd0MBCQxCnTRj0KmgYJE7sKCXljc+C+WX7G4iP50woO2eAm XM0g== X-Gm-Message-State: AOAM532LCbF+pCOuaBHRoKtse5Cj2CRj0NLloDnm9AvGqh8JOy/TX66H beCdHeUUPw0VptED+otYQycJcZqLWKROWA== X-Google-Smtp-Source: ABdhPJyvDwZGTaDvN880EbLjKU86Z7Cc27PSQTSY6jjITwL8nwi/vs6iA6fU9DSa5sQKXXdChFUa9Q== X-Received: by 2002:a1c:5406:: with SMTP id i6mr1341502wmb.5.1602616524073; Tue, 13 Oct 2020 12:15:24 -0700 (PDT) Original-Received: from unfall (218.139.134.37.dynamic.jazztel.es. [37.134.139.218]) by smtp.gmail.com with ESMTPSA id g139sm363972wme.2.2020.10.13.12.15.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Oct 2020 12:15:23 -0700 (PDT) In-Reply-To: <87h7qy0wlc.fsf@gmail.com> ("Miguel =?utf-8?Q?=C3=81ngel?= Arruga Vivas"'s message of "Tue, 13 Oct 2020 21:11:59 +0200") Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=rosen644835@gmail.com; helo=mail-wm1-x332.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.io gmane.lisp.guile.devel:20594 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Here it's the patch about the memory leak. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Fix-memory-leak-after-an-error.patch Content-Transfer-Encoding: quoted-printable Content-Description: 0001-mml.patch From=20888f31dfedc1292cff9fce2d2ef20f986c2fb669 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Miguel=3D20=3DC3=3D81ngel=3D20Arruga=3D20Vivas?=3D 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. =2D-- 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 =2D-- 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)); =20 #define SCM_DEFINE_LOCALE_CATEGORY(_name) \ { \ @@ -319,21 +322,26 @@ get_current_locale_settings (scm_t_locale_settings *s= ettings) if (locale_name =3D=3D NULL) \ goto handle_error; \ \ =2D settings-> _name =3D strdup (locale_name); \ =2D if (settings-> _name =3D=3D NULL) \ + val. _name =3D strdup (locale_name); \ + if (val. _name =3D=3D NULL) \ goto handle_oom; \ } =20 #include "locale-categories.h" #undef SCM_DEFINE_LOCALE_CATEGORY =20 + memcpy(settings, &val, sizeof (val)); return 0; =20 handle_error: =2D return EINVAL; + error =3D EINVAL; + goto cleanup; =20 handle_oom: =2D return ENOMEM; + error =3D ENOMEM; + cleanup: + free_locale_settings(&val); + return error; } =20 /* Restore locale settings SETTINGS. On success, return zero. */ =2D-=20 2.28.0 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGzBAEBCgAdFiEEiIeExBRZrMuD5+hMY0xuiXn6vsIFAl+F/IoACgkQY0xuiXn6 vsIARAv/cilrKp1FcvcGog5CC/ZKNIx7tb4GViWDji/jvfvUQDHC/hNkDYwPGrmh ntTjv3WQqRsPBLYacxcwbEaEbAbBib+2nki8zyJL2WNoiJeXTlFbGiGD/K+YFIHX 4fZZtm0Be/B4CZUDzYJhc4r73B3aqcqhkIQFkC2/Y8b+rOnIpxKKbvGlxJKGtCPb 9yEg8duy1VAykz4D52ooBNgL9quuDjCEsr533fBz5qfWZs97qOCcPM1vKujqwRLC OLgtYqkI54u+Kyw3Ivrlf8oQBi1k/2398HZgDtFhrQaV06GmgPGMcsUzoIAmp85i dhygGVQ4kq3bCca/mHjjtUpiv3tiw1TC57scHoQobKhkZsTnHixUTQ9a39pNtU9i vlOkOv21moWfWhoAe2nHrzGQwEEQqyOhU4HUFivwrOU6C9hcADhsyAmgymgb8bUd SHB4GjIrA986Em/1tLH69G8zAgyDV8bYyYW4V/1OeEpUcqJoxOTqAGe7v4+UM5Ml CwxTHkJf =qW3m -----END PGP SIGNATURE----- --==-=-=--