LZFILE *lzfile;
lzma_ret ret;
- if (!path && fd < 0)
+ if ((!path && fd < 0) || (path && fd >= 0))
return 0;
for (; *mode; mode++)
{
else if (*mode >= '1' && *mode <= '9')
level = *mode - '0';
}
- if (fd != -1)
- fp = fdopen(fd, encoding ? "w" : "r");
- else
- fp = fopen(path, encoding ? "w" : "r");
- if (!fp)
- return 0;
- lzfile = calloc(1, sizeof(*lzfile));
- if (!lzfile)
- {
- fclose(fp);
- return 0;
- }
- lzfile->file = fp;
+ lzfile = solv_calloc(1, sizeof(*lzfile));
lzfile->encoding = encoding;
lzfile->eof = 0;
lzfile->strm = stream_init;
ret = lzma_auto_decoder(&lzfile->strm, 100 << 20, 0);
if (ret != LZMA_OK)
{
- fclose(fp);
- free(lzfile);
+ solv_free(lzfile);
return 0;
}
+ if (!path)
+ fp = fdopen(fd, encoding ? "w" : "r");
+ else
+ fp = fopen(path, encoding ? "w" : "r");
+ if (!fp)
+ {
+ lzma_end(&lzfile->strm);
+ solv_free(lzfile);
+ return 0;
+ }
+ lzfile->file = fp;
return lzfile;
}
}
lzma_end(&lzfile->strm);
rc = fclose(lzfile->file);
- free(lzfile);
+ solv_free(lzfile);
return rc;
}
FILE *fp;
ZSTDFILE *zstdfile;
- if (!path && fd < 0)
+ if ((!path && fd < 0) || (path && fd >= 0))
return 0;
for (; *mode; mode++)
{
else if (*mode >= '1' && *mode <= '9')
level = *mode - '0';
}
- if (fd != -1)
- fp = fdopen(fd, encoding ? "w" : "r");
- else
- fp = fopen(path, encoding ? "w" : "r");
- if (!fp)
- return 0;
zstdfile = solv_calloc(1, sizeof(*zstdfile));
zstdfile->encoding = encoding;
if (encoding)
if (!zstdfile->cstream)
{
solv_free(zstdfile);
- fclose(fp);
return 0;
}
if (ZSTD_isError(ZSTD_initCStream(zstdfile->cstream, level)))
{
ZSTD_freeCStream(zstdfile->cstream);
solv_free(zstdfile);
- fclose(fp);
return 0;
}
zstdfile->out.dst = zstdfile->buf;
{
ZSTD_freeDStream(zstdfile->dstream);
solv_free(zstdfile);
- fclose(fp);
return 0;
}
zstdfile->in.src = zstdfile->buf;
zstdfile->in.pos = 0;
zstdfile->in.size = 0;
}
+ if (!path)
+ fp = fdopen(fd, encoding ? "w" : "r");
+ else
+ fp = fopen(path, encoding ? "w" : "r");
+ if (!fp)
+ {
+ if (encoding)
+ ZSTD_freeCStream(zstdfile->cstream);
+ else
+ ZSTD_freeDStream(zstdfile->dstream);
+ solv_free(zstdfile);
+ return 0;
+ }
zstdfile->file = fp;
return zstdfile;
}
ZSTD_freeDStream(zstdfile->dstream);
}
rc = fclose(zstdfile->file);
- free(zstdfile);
+ solv_free(zstdfile);
return rc;
}
{
zckCtx *f;
- if (!path && fd < 0)
+ if ((!path && fd < 0) || (path && fd >= 0))
return 0;
- if (fd == -1)
+ if (path)
{
if (*mode != 'w')
fd = open(path, O_RDONLY);
f = zck_create();
if (!f)
{
- close(fd);
+ if (path)
+ close(fd);
return 0;
}
if (*mode != 'w')
{
if(!zck_init_read(f, fd))
- return 0;
+ {
+ zck_free(&f);
+ if (path)
+ close(fd);
+ return 0;
+ }
}
else
{
if(!zck_init_write(f, fd))
- return 0;
+ {
+ zck_free(&f);
+ if (path)
+ close(fd);
+ return 0;
+ }
}
return cookieopen(f, mode, cookie_zckread, cookie_zckwrite, cookie_zckclose);
}
{
FILE *fp;
void *f;
- if (!path && fd < 0)
+ if ((!path && fd < 0) || (path && fd >= 0))
return 0;
- if (fd != -1)
+ if (strcmp(mode, "r") != 0)
+ return 0;
+ if (!path)
fp = fdopen(fd, mode);
else
fp = fopen(path, mode);
if (!fp)
return 0;
- if (strcmp(mode, "r") != 0)
- return 0;
f = solv_zchunk_open(fp, 1);
if (!f)
- 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);
}
SolverRuleinfo rclass;
Queue q;
int i;
+ char *prefix;
queue_init(&q);
for (rid = 1; (rclass = solver_ruleclass(solv, rid)) != SOLVER_RULE_UNKNOWN; rid++)
{
- char *prefix = solv_dupjoin("rule ", testcase_rclass2str(rclass), " ");
- prefix = solv_dupappend(prefix, testcase_ruleid(solv, rid), 0);
solver_ruleliterals(solv, rid, &q);
if (rclass == SOLVER_RULE_FEATURE && q.count == 1 && q.elements[0] == -SYSTEMSOLVABLE)
continue;
+ prefix = solv_dupjoin("rule ", testcase_rclass2str(rclass), " ");
+ prefix = solv_dupappend(prefix, testcase_ruleid(solv, rid), 0);
for (i = 0; i < q.count; i++)
{
Id p = q.elements[i];