1 |
commit: 784f3743879ec97e08197d3b21ccec54ffce914d |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri Nov 29 13:55:34 2019 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Nov 29 13:55:34 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=784f3743 |
7 |
|
8 |
main: fix memleak for main_overlay in the correct way |
9 |
|
10 |
the previous fix introduced a double free, the real problem is that the |
11 |
original main_overlay pointer was taken before its default value was |
12 |
assigned |
13 |
|
14 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
15 |
|
16 |
main.c | 7 ++++--- |
17 |
1 file changed, 4 insertions(+), 3 deletions(-) |
18 |
|
19 |
diff --git a/main.c b/main.c |
20 |
index 1f20b38..ba15c8c 100644 |
21 |
--- a/main.c |
22 |
+++ b/main.c |
23 |
@@ -617,7 +617,7 @@ read_one_repos_conf(const char *repos_conf) |
24 |
nsec = iniparser_getnsec(dict); |
25 |
while (nsec-- > 0) { |
26 |
repo = iniparser_getsecname(dict, nsec); |
27 |
- if (!strcmp(repo, "DEFAULT")) |
28 |
+ if (strcmp(repo, "DEFAULT") == 0) /* already handled above */ |
29 |
continue; |
30 |
|
31 |
xasprintf(&conf, "%s:location", repo); |
32 |
@@ -646,7 +646,6 @@ read_one_repos_conf(const char *repos_conf) |
33 |
xarraypush_str(overlay_src, repos_conf); |
34 |
} |
35 |
if (main_repo && strcmp(repo, main_repo) == 0) { |
36 |
- free(main_overlay); |
37 |
main_overlay = ele; |
38 |
free(vars_to_read[11 /* PORTDIR */].src); |
39 |
vars_to_read[11 /* PORTDIR */].src = xstrdup(repos_conf); |
40 |
@@ -720,7 +719,7 @@ initialize_portage_env(void) |
41 |
env_vars *var; |
42 |
char pathbuf[_Q_PATH_MAX]; |
43 |
const char *configroot = getenv("PORTAGE_CONFIGROOT"); |
44 |
- char *orig_main_overlay = main_overlay; |
45 |
+ char *orig_main_overlay; |
46 |
|
47 |
/* initialize all the strings with their default value */ |
48 |
for (i = 0; vars_to_read[i].name; ++i) { |
49 |
@@ -741,6 +740,7 @@ initialize_portage_env(void) |
50 |
|
51 |
/* read overlays first so we can resolve repo references in profile |
52 |
* parent files */ |
53 |
+ orig_main_overlay = main_overlay; |
54 |
snprintf(pathbuf, sizeof(pathbuf), "%.*s", (int)i, configroot); |
55 |
read_repos_conf(pathbuf, "/usr/share/portage/config/repos.conf"); |
56 |
read_repos_conf(pathbuf, "/etc/portage/repos.conf"); |
57 |
@@ -752,6 +752,7 @@ initialize_portage_env(void) |
58 |
xarraypush_str(overlay_src, STR_DEFAULT); |
59 |
} else if (orig_main_overlay == main_overlay) { |
60 |
/* if no explicit overlay was flagged as main, take the first one */ |
61 |
+ free(orig_main_overlay); |
62 |
main_overlay = array_get_elem(overlays, 0); |
63 |
set_portage_env_var(&vars_to_read[11] /* PORTDIR */, main_overlay, |
64 |
(char *)array_get_elem(overlay_src, 0)); |