From: Michael Tremer Date: Fri, 23 Apr 2021 15:52:49 +0000 (+0000) Subject: repo: Refactor local detection and fix memory leak X-Git-Tag: 0.9.28~1285^2~241 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80743432f34c0e09879d3458b260d1dd7537403c;p=pakfire.git repo: Refactor local detection and fix memory leak Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index eaa2a60ae..7251388f1 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -637,16 +637,18 @@ PAKFIRE_EXPORT int pakfire_repo_set_baseurl(PakfireRepo repo, const char* baseur return 0; } -static char* pakfire_repo_get_path(PakfireRepo repo) { - const char* baseurl = pakfire_repo_get_baseurl(repo); - if (!baseurl) - return NULL; +static int pakfire_repo_is_local(PakfireRepo repo) { + if (!*repo->appdata->baseurl) + return 0; + + return pakfire_string_startswith(repo->appdata->baseurl, "file://"); +} - // Must be a local repository - if (!pakfire_string_startswith(baseurl, "file://")) +static const char* pakfire_repo_get_path(PakfireRepo repo) { + if (!pakfire_repo_is_local(repo)) return NULL; - return strdup(baseurl + strlen("file://")); + return repo->appdata->baseurl + strlen("file://"); } PAKFIRE_EXPORT const char* pakfire_repo_get_keyfile(PakfireRepo repo) { @@ -835,7 +837,7 @@ static int pakfire_repo_scan_file(PakfireRepo repo, const char* path) { PAKFIRE_EXPORT int pakfire_repo_scan(PakfireRepo repo, int flags) { struct pakfire_progressbar* progressbar = NULL; - char* path = pakfire_repo_get_path(repo); + const char* path = pakfire_repo_get_path(repo); if (!path) { errno = EINVAL; return 1;