commit: 291f2707236477bc654976b70d68526cb3115531
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon Nov 25 19:33:28 2019 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon Nov 25 19:33:28 2019 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=291f2707
main: fix unintended memory freeing
env_vars keep pointers to global variables, so modifying those variables
is enough to change the values
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
main.c | 34 +++++++++++++++++++++++++---------
tests/quse/dotest | 4 ----
2 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/main.c b/main.c
index 081d72a..fb2340b 100644
--- a/main.c
+++ b/main.c
@@ -333,8 +333,7 @@ set_portage_env_var(env_vars *var, const char *value, const
char *src)
var->src = xstrdup(src);
break;
case _Q_ISTR:
- strincr_var(var->name, value, var->value.s, &var->value_len);
- if (strcmp(var->src, "built-in default") == 0) {
+ if (*var->value.s == NULL) {
free(var->src);
var->src = xstrdup(src);
} else {
@@ -344,6 +343,7 @@ set_portage_env_var(env_vars *var, const char *value, const
char *src)
free(var->src);
var->src = p;
}
+ strincr_var(var->name, value, var->value.s, &var->value_len);
break;
}
}
@@ -616,14 +616,30 @@ read_one_repos_conf(const char *repos_conf)
xasprintf(&conf, "%s:location", repo);
path = iniparser_getstring(dict, conf, NULL);
if (path) {
- void *ele = xarraypush_str(overlays, path);
- xarraypush_str(overlay_names, repo);
- xarraypush_str(overlay_src, repos_conf);
- if (main_repo && !strcmp(repo, main_repo)) {
- main_overlay = ele;
- set_portage_env_var(&vars_to_read[11] /*
PORTDIR */,
- main_overlay, repos_conf);
+ void *ele;
+ size_t n;
+ char *overlay;
+
+ array_for_each(overlay_names, n, overlay) {
+ if (strcmp(overlay, repo) == 0)
+ break;
+ overlay = NULL;
}
+ if (overlay != NULL) {
+ /* replace overlay */
+ ele = array_get_elem(overlay_src, n);
+ free(ele);
+ array_get_elem(overlay_src, n) =
xstrdup(repos_conf);
+ ele = array_get_elem(overlays, n);
+ free(ele);
+ ele = array_get_elem(overlays, n) =
xstrdup(path);
+ } else {
+ ele = xarraypush_str(overlays, path);
+ xarraypush_str(overlay_names, repo);
+ xarraypush_str(overlay_src, repos_conf);
+ }
+ if (main_repo && strcmp(repo, main_repo) == 0)
+ main_overlay = ele;
}
free(conf);
}
diff --git a/tests/quse/dotest b/tests/quse/dotest
index 2a5cc5e..ada7bd9 100755
--- a/tests/quse/dotest
+++ b/tests/quse/dotest
@@ -13,10 +13,6 @@ entries() {
sed -e 's:#.*::' -e '/^$/d' "$1"
}
-# temp for Travis debugging
-q -Cov
-q -Cev
-
# check use.desc
f="$d/use.desc"
all=$(entries "$f" | awk '{print $1}')