-
Notifications
You must be signed in to change notification settings - Fork 1k
fwrite(): when col.names=FALSE, produce a gzip header, avoid a leak
#6853
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
855886d
fwrite(): emit gzip header even if !col.names
aitap 828d455
Avoid a memory leak in fwrite(compress="gzip")
aitap 8d5d3f5
NEWS entry
aitap 551aa87
comment the source of this #endif for clarity
MichaelChirico 0b3d598
Clean up the test file
aitap 133878a
Report write() errno instead of just plain -1
aitap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -829,9 +829,28 @@ void fwriteMain(fwriteMainArgs args) | |
| zbuffSize / MEGA, nth, errno, strerror(errno)); | ||
| // # nocov end | ||
| } | ||
| } | ||
| len = 0; | ||
| crc = crc32(0L, Z_NULL, 0); | ||
|
|
||
| #endif | ||
| if (f != -1) { | ||
| // write minimal gzip header, but not on the console | ||
| static const char header[] = "\037\213\10\0\0\0\0\0\0\3"; | ||
| int ret0 = WRITE(f, header, (sizeof header) - 1); | ||
| compress_len += (sizeof header) - 1; | ||
|
|
||
| if (ret0 == -1) { | ||
| // # nocov start | ||
| int errwrite = errno; // capture write errno now in case close fails with a different errno | ||
MichaelChirico marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| CLOSE(f); | ||
| free(buffPool); | ||
| free(zbuffPool); | ||
| deflateEnd(&strm); | ||
| STOP(_("Failed to write gzip header. Write returned %d"), errwrite); | ||
| // # nocov end | ||
| } | ||
| } | ||
| } | ||
| #endif // #NOZLIB | ||
|
|
||
| // write header | ||
|
|
||
|
|
@@ -873,15 +892,10 @@ void fwriteMain(fwriteMainArgs args) | |
| *ch = '\0'; | ||
| DTPRINT("%s", buff); // # notranslate | ||
| } else { | ||
| int ret0=0, ret1=0, ret2=0; | ||
| int ret1=0, ret2=0; | ||
| #ifndef NOZLIB | ||
| if (args.is_gzip) { | ||
| char* zbuff = zbuffPool; | ||
| // write minimal gzip header | ||
| char* header = "\037\213\10\0\0\0\0\0\0\3"; | ||
| ret0 = WRITE(f, header, 10); | ||
| compress_len += 10; | ||
| crc = crc32(0L, Z_NULL, 0); | ||
|
|
||
| size_t zbuffUsed = zbuffSize; | ||
| len = (size_t)(ch - buff); | ||
|
|
@@ -898,21 +912,26 @@ void fwriteMain(fwriteMainArgs args) | |
| #ifndef NOZLIB | ||
| } | ||
| #endif | ||
| if (ret0 == -1 || ret1 || ret2 == -1) { | ||
| if (ret1 || ret2 == -1) { | ||
| // # nocov start | ||
| int errwrite = errno; // capture write errno now in case close fails with a different errno | ||
| CLOSE(f); | ||
| free(buffPool); | ||
| #ifndef NOZLIB | ||
| free(zbuffPool); | ||
| #endif | ||
| if (ret0 == -1) STOP(_("Failed to write gzip header. Write returned %d"), ret0); | ||
| else if (ret1) STOP(_("Failed to compress gzip. compressbuff() returned %d"), ret1); | ||
| if (ret1) STOP(_("Failed to compress gzip. compressbuff() returned %d"), ret1); | ||
| else STOP(_("%s: '%s'"), strerror(errwrite), args.filename); | ||
| // # nocov end | ||
| } | ||
| } | ||
| } | ||
| #ifndef NOZLIB | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And if |
||
| else { | ||
| // was unconditionally initialized for zbuffSize, not used for header | ||
| deflateEnd(&strm); | ||
| } | ||
| #endif | ||
| if (verbose) | ||
| DTPRINT(_("Initialization done in %.3fs\n"), 1.0*(wallclock()-t0)); | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.