Skip to content

Commit dc24d2d

Browse files
committed
libebgenv: Only release CONFIG_PART::mountpoint early on errors
This fixes a regression caused by premature cleanup: If probe_config_file() ran successfully and found an already mounted partition, its mountpoint must not be released yet. bgenv_finalize() will take care of that. However, if probe_config_file() failed, it must free any previously created mountpoint string prior to returning. That is what c2be7c1 was actually trying to resolve. But as we are no longer freeing in probe_config_file on success, we need to free on errors in probe_config_partitions. This was found by coverity after only changing probe_config_file. Reported-by: Ingo Rah <ingo.rah@linutronix.de> Fixes: c2be7c1 ("libebgenv: fix memory leak in partition probing") Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
1 parent c6fc548 commit dc24d2d

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

env/env_config_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ bool probe_config_file(CONFIG_PART *cfgpart)
8585
}
8686
if (do_unmount) {
8787
unmount_partition(cfgpart);
88-
} else {
88+
} else if (!result) {
8989
free(cfgpart->mountpoint);
9090
cfgpart->mountpoint = NULL;
9191
}

env/env_config_partitions.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ bool probe_config_partitions(CONFIG_PART *cfgpart, bool search_all_devices)
149149
cfgpart[count] = tmp;
150150
} else {
151151
free(tmp.devpath);
152+
free(tmp.mountpoint);
152153
VERBOSE(stderr,
153154
"Error, there are "
154155
"more than %d config "

0 commit comments

Comments
 (0)