From: Michael Schroeder Date: Tue, 6 Apr 2021 14:01:29 +0000 (+0200) Subject: Make zchunkopen a bit easier to understand X-Git-Tag: 0.7.19~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=93159d978b0ce0b10bba47f2777d75ecbce724db;p=thirdparty%2Flibsolv.git Make zchunkopen a bit easier to understand --- diff --git a/ext/solv_xfopen.c b/ext/solv_xfopen.c index 7dca41f0..369003b4 100644 --- a/ext/solv_xfopen.c +++ b/ext/solv_xfopen.c @@ -598,7 +598,6 @@ static void *zchunkopen(const char *path, const char *mode, int fd) { FILE *fp; void *f; - int tmpfd; if ((!path && fd < 0) || (path && fd >= 0)) return 0; if (strcmp(mode, "r") != 0) @@ -612,17 +611,20 @@ static void *zchunkopen(const char *path, const char *mode, int fd) f = solv_zchunk_open(fp, 1); if (!f) { - /* When 0 is returned, fd passed by user must not be closed! */ - /* Dup (save) the original fd to a temporary variable and then back. */ - /* It is ugly and thread unsafe hack (non atomical sequence fclose dup2). */ - if (!path) - tmpfd = dup(fd); - fclose(fp); if (!path) { + /* The fd passed by user must not be closed! */ + /* Dup (save) the original fd to a temporary variable and then back. */ + /* It is ugly and thread unsafe hack (non atomical sequence fclose dup2). */ + int tmpfd = dup(fd); + fclose(fp); dup2(tmpfd, fd); close(tmpfd); } + else + { + fclose(fp); + } } return cookieopen(f, mode, (ssize_t (*)(void *, char *, size_t))solv_zchunk_read, 0, (int (*)(void *))solv_zchunk_close); }