From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id D288D15800F for ; Tue, 10 Jan 2023 05:21:45 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B0AE7E0824; Tue, 10 Jan 2023 05:21:44 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 9AAD8E0824 for ; Tue, 10 Jan 2023 05:21:44 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id A905E340E37 for ; Tue, 10 Jan 2023 05:21:43 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 38FF5827 for ; Tue, 10 Jan 2023 05:21:42 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1673328099.776afeae92d2afd3340cd753abc58ccd8daba48f.sam@gentoo> Subject: [gentoo-commits] proj/elfix:master commit in: misc/install-xattr/ X-VCS-Repository: proj/elfix X-VCS-Files: misc/install-xattr/install-xattr.c X-VCS-Directories: misc/install-xattr/ X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: 776afeae92d2afd3340cd753abc58ccd8daba48f X-VCS-Branch: master Date: Tue, 10 Jan 2023 05:21:42 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 8e658623-29fa-4c81-91c1-3168c72177e1 X-Archives-Hash: 52b3467d8c8c0eb914b1ded8bcc477b0 commit: 776afeae92d2afd3340cd753abc58ccd8daba48f Author: Sam James gentoo org> AuthorDate: Fri Jan 6 06:39:30 2023 +0000 Commit: Sam James gentoo 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 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);