Gentoo Archives: gentoo-commits

From: Fabian Groffen <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: /, tests/quse/
Date: Mon, 25 Nov 2019 19:39:55
Message-Id: 1574710408.291f2707236477bc654976b70d68526cb3115531.grobian@gentoo
1 commit: 291f2707236477bc654976b70d68526cb3115531
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Mon Nov 25 19:33:28 2019 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Mon Nov 25 19:33:28 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=291f2707
7
8 main: fix unintended memory freeing
9
10 env_vars keep pointers to global variables, so modifying those variables
11 is enough to change the values
12
13 Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
14
15 main.c | 34 +++++++++++++++++++++++++---------
16 tests/quse/dotest | 4 ----
17 2 files changed, 25 insertions(+), 13 deletions(-)
18
19 diff --git a/main.c b/main.c
20 index 081d72a..fb2340b 100644
21 --- a/main.c
22 +++ b/main.c
23 @@ -333,8 +333,7 @@ set_portage_env_var(env_vars *var, const char *value, const char *src)
24 var->src = xstrdup(src);
25 break;
26 case _Q_ISTR:
27 - strincr_var(var->name, value, var->value.s, &var->value_len);
28 - if (strcmp(var->src, "built-in default") == 0) {
29 + if (*var->value.s == NULL) {
30 free(var->src);
31 var->src = xstrdup(src);
32 } else {
33 @@ -344,6 +343,7 @@ set_portage_env_var(env_vars *var, const char *value, const char *src)
34 free(var->src);
35 var->src = p;
36 }
37 + strincr_var(var->name, value, var->value.s, &var->value_len);
38 break;
39 }
40 }
41 @@ -616,14 +616,30 @@ read_one_repos_conf(const char *repos_conf)
42 xasprintf(&conf, "%s:location", repo);
43 path = iniparser_getstring(dict, conf, NULL);
44 if (path) {
45 - void *ele = xarraypush_str(overlays, path);
46 - xarraypush_str(overlay_names, repo);
47 - xarraypush_str(overlay_src, repos_conf);
48 - if (main_repo && !strcmp(repo, main_repo)) {
49 - main_overlay = ele;
50 - set_portage_env_var(&vars_to_read[11] /* PORTDIR */,
51 - main_overlay, repos_conf);
52 + void *ele;
53 + size_t n;
54 + char *overlay;
55 +
56 + array_for_each(overlay_names, n, overlay) {
57 + if (strcmp(overlay, repo) == 0)
58 + break;
59 + overlay = NULL;
60 }
61 + if (overlay != NULL) {
62 + /* replace overlay */
63 + ele = array_get_elem(overlay_src, n);
64 + free(ele);
65 + array_get_elem(overlay_src, n) = xstrdup(repos_conf);
66 + ele = array_get_elem(overlays, n);
67 + free(ele);
68 + ele = array_get_elem(overlays, n) = xstrdup(path);
69 + } else {
70 + ele = xarraypush_str(overlays, path);
71 + xarraypush_str(overlay_names, repo);
72 + xarraypush_str(overlay_src, repos_conf);
73 + }
74 + if (main_repo && strcmp(repo, main_repo) == 0)
75 + main_overlay = ele;
76 }
77 free(conf);
78 }
79
80 diff --git a/tests/quse/dotest b/tests/quse/dotest
81 index 2a5cc5e..ada7bd9 100755
82 --- a/tests/quse/dotest
83 +++ b/tests/quse/dotest
84 @@ -13,10 +13,6 @@ entries() {
85 sed -e 's:#.*::' -e '/^$/d' "$1"
86 }
87
88 -# temp for Travis debugging
89 -q -Cov
90 -q -Cev
91 -
92 # check use.desc
93 f="$d/use.desc"
94 all=$(entries "$f" | awk '{print $1}')