public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Sam James" <sam@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/elfix:master commit in: misc/install-xattr/
Date: Tue, 10 Jan 2023 05:21:42 +0000 (UTC)	[thread overview]
Message-ID: <1673328099.776afeae92d2afd3340cd753abc58ccd8daba48f.sam@gentoo> (raw)

commit:     776afeae92d2afd3340cd753abc58ccd8daba48f
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Fri Jan  6 06:39:30 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Jan 10 05:21:39 2023 +0000
URL:        https://gitweb.gentoo.org/proj/elfix.git/commit/?id=776afeae

install-xattr: fix small memory leak

There's another with strdup/malloc but it gets a bit messier
to fix so let's leave that for now (this is mostly about correctness
anyway, as the runtime of install-xattr is very small):
```
Direct leak of 4097 byte(s) in 1 object(s) allocated from:
    #0 0x7f4a2c22e257 in __interceptor_malloc /usr/src/debug/sys-devel/gcc-13.0.0_pre20230101/gcc-13-20230101/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f4a2c1d2b40 in __interceptor_realpath /usr/src/debug/sys-devel/gcc-13.0.0_pre20230101/gcc-13-20230101/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:3904
    #2 0x55da3adf5629 in realpath /usr/include/bits/stdlib.h:42
    #3 0x55da3adf5629 in main /home/sam/git/elfix/misc/install-xattr/install-xattr.c:252
```

Signed-off-by: Sam James <sam <AT> gentoo.org>

 misc/install-xattr/install-xattr.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/misc/install-xattr/install-xattr.c b/misc/install-xattr/install-xattr.c
index db6dabd..23b6af3 100644
--- a/misc/install-xattr/install-xattr.c
+++ b/misc/install-xattr/install-xattr.c
@@ -248,7 +248,6 @@ main(int argc, char* argv[])
 	char *target = NULL;           /* the target file or directory                                 */
 	char *path;                    /* path to the target file                                      */
 
-	char *mypath = realpath("/proc/self/exe", NULL); /* path to argv[0]                            */
 	char *install;                                   /* path to the system install                 */
 
 	struct stat s;                 /* test if a file is a regular file or a directory              */
@@ -353,7 +352,9 @@ main(int argc, char* argv[])
 		case -1:
 			err(1, "fork() failed");
 
-		case 0:
+		case 0: {
+			char *mypath = realpath("/proc/self/exe", NULL); /* path to argv[0] */
+
 			/* find system install avoiding mypath and portage_helper_path! */
 			if (portage_helper_path)
 				portage_helper_canpath = realpath(portage_helper_path, NULL);
@@ -363,6 +364,7 @@ main(int argc, char* argv[])
 			argv[0] = install;        /* so coreutils' lib/program.c behaves  */
 			execv(install, argv);     /* The kernel will free(install).       */
 			err(1, "execv() failed");
+		}
 
 		default:
 			wait(&status);


             reply	other threads:[~2023-01-10  5:21 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-10  5:21 Sam James [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-01-29  3:57 [gentoo-commits] proj/elfix:master commit in: misc/install-xattr/ Sam James
2023-01-24  3:05 Sam James
2023-01-24  3:05 Sam James
2023-01-11  6:53 Sam James
2023-01-10  5:21 Sam James
2019-11-10  0:59 Anthony G. Basile
2019-11-10  0:54 Anthony G. Basile
2019-11-10  0:54 Anthony G. Basile
2019-11-09 18:24 Anthony G. Basile
2019-11-09 18:24 Anthony G. Basile
2019-04-14 18:40 Anthony G. Basile
2019-03-30 10:12 Anthony G. Basile
2015-06-08 13:07 Anthony G. Basile
2015-05-29 11:32 Anthony G. Basile
2014-11-02 21:46 Anthony G. Basile
2014-10-13  2:28 Anthony G. Basile
2014-10-13  2:20 Anthony G. Basile
2014-10-09  2:40 Anthony G. Basile
2014-07-21 21:25 Anthony G. Basile
2014-06-27 12:26 Anthony G. Basile
2014-06-27 12:26 Anthony G. Basile
2014-06-24 21:49 Anthony G. Basile
2014-06-15 22:09 Anthony G. Basile
2014-06-11 11:25 Anthony G. Basile
2014-06-10 21:04 Anthony G. Basile
2014-06-10  1:49 Anthony G. Basile
2014-06-10  1:49 Anthony G. Basile
2014-06-08 20:27 Anthony G. Basile
2014-06-01  0:26 Anthony G. Basile
2014-02-13 19:08 Anthony G. Basile
2014-02-13 19:01 Anthony G. Basile
2014-02-13 18:48 Anthony G. Basile

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1673328099.776afeae92d2afd3340cd753abc58ccd8daba48f.sam@gentoo \
    --to=sam@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.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