Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file descriptor leak in compress.mod #1614

Merged
merged 3 commits into from
Jul 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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