]> git.ipfire.org Git - pakfire.git/commitdiff
archive: Don't try to set fadvise() on an invalid fd
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 12 Jan 2025 11:27:07 +0000 (11:27 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 12 Jan 2025 11:27:07 +0000 (11:27 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/archive.c

index 4c76fcd15764f573e8f2fb9c09bb03193cc1abd8..f7822c24e831e9a36047d2666231762adbedea8e 100644 (file)
@@ -179,6 +179,12 @@ static int archive_read_file_open(struct archive* a, FILE* f) {
                goto ERROR;
        }
 
+       // Let the kernel know, that we will read the file sequentially
+       r = posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
+       if (r < 0) {
+               r = -errno;
+               goto ERROR;
+       }
 
        // Re-open the file handle
        f = fdopen(fd, "r");
@@ -197,15 +203,14 @@ static int archive_read_file_open(struct archive* a, FILE* f) {
 
        // Allocate an object
        file = calloc(1, sizeof(*file));
-       if (!file)
+       if (!file) {
+               r = -errno;
                goto ERROR;
+       }
 
        // Store the file handle
        file->f = f;
 
-       // Let the kernel know, that we will read the file sequentially
-       posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
-
        // Open the archive
        return archive_read_open2(a,
                file, NULL, archive_file_read, archive_file_skip, archive_file_close);