Skip to content

Commit

Permalink
Fix file descriptor leak in compress.mod
Browse files Browse the repository at this point in the history
Patch by: michaelortmann
  • Loading branch information
michaelortmann authored Jul 28, 2024
1 parent 36e0034 commit 6fd2092
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/mod/compress.mod/compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ static int is_compressedfile(char *filename)
if (!zin)
return COMPF_FAILED;
len1 = gzread(zin, buf1, sizeof(buf1));
if (len1 < 0)
if (len1 < 0) {
gzclose(zin);
return COMPF_FAILED;
}
if (gzclose(zin) != Z_OK)
return COMPF_FAILED;

Expand Down Expand Up @@ -142,6 +144,7 @@ static int uncompress_to_file(char *f_src, char *f_target)

fout = fopen(f_target, "wb");
if (!fout) {
gzclose(fin);
putlog(LOG_MISC, "*", "Failed to uncompress file `%s': open failed: %s.",
f_src, strerror(errno));
return COMPF_ERROR;
Expand All @@ -152,6 +155,7 @@ static int uncompress_to_file(char *f_src, char *f_target)
if (len < 0) {
putlog(LOG_MISC, "*", "Failed to uncompress file `%s': gzread failed.",
f_src);
gzclose(fin);
fclose(fout);
return COMPF_ERROR;
}
Expand All @@ -160,13 +164,15 @@ static int uncompress_to_file(char *f_src, char *f_target)
if ((int) fwrite(buf, 1, (unsigned int) len, fout) != len) {
putlog(LOG_MISC, "*", "Failed to uncompress file `%s': fwrite "
"failed: %s.", f_src, strerror(errno));
gzclose(fin);
fclose(fout);
return COMPF_ERROR;
}
}
if (fclose(fout)) {
putlog(LOG_MISC, "*", "Failed to uncompress file `%s': fclose failed: %s.",
f_src, strerror(errno));
gzclose(fin);
return COMPF_ERROR;
}
if (gzclose(fin) != Z_OK) {
Expand Down

0 comments on commit 6fd2092

Please sign in to comment.