]> git.ipfire.org Git - pakfire.git/commitdiff
repo: Refactor local detection and fix memory leak
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 23 Apr 2021 15:52:49 +0000 (15:52 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 23 Apr 2021 15:52:49 +0000 (15:52 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/repo.c

index eaa2a60aef99ecfa2cd478036feafccea6f20e1a..7251388f1401be4c223d19321e449e3b97eab020 100644 (file)
@@ -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;