GNU bug report logs - #47384
[PATCH 1/2] hostname: fix a memory leak with -Dlint

Previous Next

Package: coreutils;

Reported by: Kamil Dudka <kdudka <at> redhat.com>

Date: Thu, 25 Mar 2021 10:59:02 UTC

Severity: normal

Tags: patch

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 47384 in the body.
You can then email your comments to 47384 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#47384; Package coreutils. (Thu, 25 Mar 2021 10:59:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Kamil Dudka <kdudka <at> redhat.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Thu, 25 Mar 2021 10:59:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Kamil Dudka <kdudka <at> redhat.com>
To: bug-coreutils <at> gnu.org
Subject: [PATCH 1/2] hostname: fix a memory leak with -Dlint
Date: Thu, 25 Mar 2021 11:57:55 +0100
* src/hostname.c (main): Free allocated memory when compiled
with -Dlint.
---
 src/hostname.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/hostname.c b/src/hostname.c
index 7d13575d4e9..8ec9aad4d34 100644
--- a/src/hostname.c
+++ b/src/hostname.c
@@ -104,6 +104,9 @@ main (int argc, char **argv)
       if (hostname == NULL)
         die (EXIT_FAILURE, errno, _("cannot determine hostname"));
       printf ("%s\n", hostname);
+#ifdef lint
+      free(hostname);
+#endif
     }
 
   if (optind + 1 < argc)
-- 
2.26.3





Information forwarded to bug-coreutils <at> gnu.org:
bug#47384; Package coreutils. (Thu, 25 Mar 2021 15:57:02 GMT) Full text and rfc822 format available.

Message #8 received at 47384 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Kamil Dudka <kdudka <at> redhat.com>
Cc: 47384 <at> debbugs.gnu.org
Subject: Re: bug#47384: [PATCH 1/2] hostname: fix a memory leak with -Dlint
Date: Thu, 25 Mar 2021 08:56:15 -0700
On 3/25/21 3:57 AM, Kamil Dudka wrote:

> +#ifdef lint
> +      free(hostname);
> +#endif

Let's not do this one. The program is about to exit so there's no need 
to free, and any static-checking tool that complains about a missing 
'free' here is issuing a false alarm. On this particular issue it's 
better to fix the tools than to clutter upb source code to pacify them.




Information forwarded to bug-coreutils <at> gnu.org:
bug#47384; Package coreutils. (Thu, 25 Mar 2021 16:09:01 GMT) Full text and rfc822 format available.

Message #11 received at 47384 <at> debbugs.gnu.org (full text, mbox):

From: Kamil Dudka <kdudka <at> redhat.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 47384 <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
Subject: Re: bug#47384: [PATCH 1/2] hostname: fix a memory leak with -Dlint
Date: Thu, 25 Mar 2021 17:08:50 +0100
On Thursday, March 25, 2021 4:56:15 PM CET Paul Eggert wrote:
> On 3/25/21 3:57 AM, Kamil Dudka wrote:
> > +#ifdef lint
> > +      free(hostname);
> > +#endif
> 
> Let's not do this one. The program is about to exit so there's no need
> to free, and any static-checking tool that complains about a missing
> 'free' here is issuing a false alarm. On this particular issue it's
> better to fix the tools than to clutter upb source code to pacify them.

Wasn't that exactly what -Dlint was for when we discussed it the last time?
I am totally lost in your reasoning again.  But thank you for having a look.

Kamil






Information forwarded to bug-coreutils <at> gnu.org:
bug#47384; Package coreutils. (Thu, 25 Mar 2021 16:10:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-coreutils <at> gnu.org:
bug#47384; Package coreutils. (Thu, 25 Mar 2021 16:10:02 GMT) Full text and rfc822 format available.

Message #17 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Kamil Dudka <kdudka <at> redhat.com>
Cc: 47384 <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
Subject: Re: bug#47384: [PATCH 1/2] hostname: fix a memory leak with -Dlint
Date: Thu, 25 Mar 2021 09:09:44 -0700
On 3/25/21 9:08 AM, Kamil Dudka wrote:
> Wasn't that exactly what -Dlint was for when we discussed it the last time?

Sorry, don't recall the last time. This is a borderline area, admittedly.




Information forwarded to bug-coreutils <at> gnu.org:
bug#47384; Package coreutils. (Thu, 25 Mar 2021 16:10:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-coreutils <at> gnu.org:
bug#47384; Package coreutils. (Thu, 25 Mar 2021 16:34:01 GMT) Full text and rfc822 format available.

Message #23 received at 47384 <at> debbugs.gnu.org (full text, mbox):

From: Kamil Dudka <kdudka <at> redhat.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 47384 <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
Subject: Re: bug#47384: [PATCH 1/2] hostname: fix a memory leak with -Dlint
Date: Thu, 25 Mar 2021 17:33:50 +0100
On Thursday, March 25, 2021 5:09:44 PM CET Paul Eggert wrote:
> On 3/25/21 9:08 AM, Kamil Dudka wrote:
> > Wasn't that exactly what -Dlint was for when we discussed it the last
> > time?
> 
> Sorry, don't recall the last time.

I meant this thread on bug-gnulib ML:

    https://lists.gnu.org/archive/html/bug-gnulib/2020-05/msg00114.html

> This is a borderline area, admittedly.

How does it differ from the following change, which you did not block?

    https://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=v8.24-21-ga4b640549df

Kamil






Information forwarded to bug-coreutils <at> gnu.org:
bug#47384; Package coreutils. (Thu, 25 Mar 2021 16:35:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-coreutils <at> gnu.org:
bug#47384; Package coreutils. (Thu, 25 Mar 2021 18:17:01 GMT) Full text and rfc822 format available.

Message #29 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Kamil Dudka <kdudka <at> redhat.com>
Cc: 47384 <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
Subject: Re: bug#47384: [PATCH 1/2] hostname: fix a memory leak with -Dlint
Date: Thu, 25 Mar 2021 11:16:46 -0700
On 3/25/21 9:33 AM, Kamil Dudka wrote:
> How does it differ from the following change, which you did not block?

Thanks for reminding me of the earlier exchange. On second thought I 
guess it's OK, though I'd prefer it to use IF_LINT (as in the earlier 
change), as that makes it cleaner since it's just one line of useless 
code, not three.




Information forwarded to bug-coreutils <at> gnu.org:
bug#47384; Package coreutils. (Thu, 25 Mar 2021 18:17:02 GMT) Full text and rfc822 format available.

Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Thu, 25 Mar 2021 18:23:02 GMT) Full text and rfc822 format available.

Notification sent to Kamil Dudka <kdudka <at> redhat.com>:
bug acknowledged by developer. (Thu, 25 Mar 2021 18:23:02 GMT) Full text and rfc822 format available.

Message #37 received at 47384-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Kamil Dudka <kdudka <at> redhat.com>
Cc: 47384-done <at> debbugs.gnu.org
Subject: Re: bug#47384: [PATCH 1/2] hostname: fix a memory leak with -Dlint
Date: Thu, 25 Mar 2021 11:22:33 -0700
[Message part 1 (text/plain, inline)]
On 3/25/21 11:16 AM, Paul Eggert wrote:
> I'd prefer it to use IF_LINT (as in the earlier 
> change), as that makes it cleaner since it's just one line of useless 
> code, not three.

Installed as attached, and closing the bug report. Thanks again.
[0001-hostname-pacify-valgrind.patch (text/x-patch, attachment)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 23 Apr 2021 11:24:13 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 3 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.