All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ross Burton" <ross@burtonini.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH][pseudo 4/7] Fix some memory leaks
Date: Fri,  8 Jan 2021 14:06:37 +0000	[thread overview]
Message-ID: <20210108140640.1069133-4-ross.burton@arm.com> (raw)
In-Reply-To: <20210108140640.1069133-1-ross.burton@arm.com>

pseudo_get_value() returns newly allocated memory that the caller must free,
so add some free() calls.

Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 pseudo.c        | 4 +++-
 pseudo_client.c | 9 +++++++++
 pseudo_util.c   | 2 ++
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/pseudo.c b/pseudo.c
index 55f0f18..f2e2f87 100644
--- a/pseudo.c
+++ b/pseudo.c
@@ -245,10 +245,12 @@ main(int argc, char *argv[]) {
 	/* Options are processed, preserve them... */
 	pseudo_set_value("PSEUDO_OPTS", opts);
 
-	if (!pseudo_get_prefix(argv[0])) {
+	s = pseudo_get_prefix(argv[0]);
+	if (!s) {
 		pseudo_diag("Can't figure out prefix.  Set PSEUDO_PREFIX or invoke with full path.\n");
 		exit(PSEUDO_EXIT_PSEUDO_PREFIX);
 	}
+	free(s);
 
 	/* move database */
 	if (opt_m || opt_M) {
diff --git a/pseudo_client.c b/pseudo_client.c
index eeb1fdc..6310b99 100644
--- a/pseudo_client.c
+++ b/pseudo_client.c
@@ -431,6 +431,7 @@ pseudo_profile_report(void) {
 void
 pseudo_init_client(void) {
 	char *env;
+	int need_free = 0;
 
 	pseudo_antimagic();
 	pseudo_new_pid();
@@ -450,9 +451,11 @@ pseudo_init_client(void) {
 	 * or it may have gone away, in which case we'd enable
 	 * pseudo (and cause it to reinit the defaults).
 	 */
+	need_free = 0;
 	env = getenv("PSEUDO_DISABLED");
 	if (!env) {
 		env = pseudo_get_value("PSEUDO_DISABLED");
+		need_free = 1;
 	}
 	if (env) {
 		int actually_disabled = 1;
@@ -487,15 +490,19 @@ pseudo_init_client(void) {
 	} else {
 		pseudo_set_value("PSEUDO_DISABLED", "0");
 	}
+	if (need_free)
+		free(env);
 
 	/* ALLOW_FSYNC is here because some crazy hosts will otherwise
 	 * report incorrect values for st_size/st_blocks. I can sort of
 	 * understand st_blocks, but bogus values for st_size? Not cool,
 	 * dudes, not cool.
 	 */
+	need_free = 0;
 	env = getenv("PSEUDO_ALLOW_FSYNC");
 	if (!env) {
 		env = pseudo_get_value("PSEUDO_ALLOW_FSYNC");
+		need_free = 1;
 	} else {
 		pseudo_set_value("PSEUDO_ALLOW_FSYNC", env);
 	}
@@ -504,6 +511,8 @@ pseudo_init_client(void) {
 	} else {
 		pseudo_allow_fsync = 0;
 	}
+	if (need_free)
+		free(env);
 
 	/* in child processes, PSEUDO_UNLOAD may become set to
 	 * some truthy value, in which case we're being asked to
diff --git a/pseudo_util.c b/pseudo_util.c
index 51c07c2..b6980c2 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -967,6 +967,7 @@ pseudo_setupenv() {
 		}
 		snprintf(newenv, len, "%s:%s64", libdir_path, libdir_path);
 		SETENV(PRELINK_PATH, newenv, 1);
+		free(newenv);
 	} else if (!strstr(ld_library_path, libdir_path)) {
 		size_t len = strlen(ld_library_path) + 1 + strlen(libdir_path) + 1 + (strlen(libdir_path) + 2) + 1;
 		char *newenv = malloc(len);
@@ -975,6 +976,7 @@ pseudo_setupenv() {
 		}
 		snprintf(newenv, len, "%s:%s:%s64", ld_library_path, libdir_path, libdir_path);
 		SETENV(PRELINK_PATH, newenv, 1);
+		free(newenv);
 	} else {
 		/* nothing to do, ld_library_path exists and contains
 		 * our preferred path */
-- 
2.25.1


  parent reply	other threads:[~2021-01-08 14:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-08 14:06 [PATCH][pseudo 1/7] pseudo_util: don't overrun strings when looking for keys Ross Burton
2021-01-08 14:06 ` [PATCH][pseudo 2/7] Silence switch block warnings Ross Burton
2021-01-08 14:06 ` [PATCH][pseudo 3/7] Disable deprecated function warnings Ross Burton
2021-01-08 14:06 ` Ross Burton [this message]
2021-01-08 16:01   ` [OE-core] [PATCH][pseudo 4/7] Fix some memory leaks Seebs
2021-01-08 14:06 ` [PATCH][pseudo 5/7] makewrappers: fix Python 2 hangover Ross Burton
2021-01-08 14:06 ` [PATCH][pseudo 6/7] makewrappers: support architecture-overrides in wrapper modifiers Ross Burton
2021-01-08 14:06 ` [PATCH][pseudo 7/7] ports/linux/xattr: add arm64 versions for xattr calls Ross Burton

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=20210108140640.1069133-4-ross.burton@arm.com \
    --to=ross@burtonini.com \
    --cc=openembedded-core@lists.openembedded.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.