summaryrefslogtreecommitdiff
path: root/libc/stdio/stdio.cpp
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2017-07-24 21:05:37 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-07-24 21:05:37 +0000
commit4fce647a5bcb61680c9f865b05c9f43a4841b244 (patch)
tree2ee2dc2b454cef278fb6a8ccde0cd101fa23e9d5 /libc/stdio/stdio.cpp
parent4dc80181cd9dfcae92596b12cf474ac211dcb186 (diff)
parent80e4c1529d1b63ee0b7f6f6ad7900885ba1c0b51 (diff)
Merge "Remove the HASLB and FREEUB macros."
Diffstat (limited to 'libc/stdio/stdio.cpp')
-rw-r--r--libc/stdio/stdio.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp
index b0f5c607f..cd4be2e76 100644
--- a/libc/stdio/stdio.cpp
+++ b/libc/stdio/stdio.cpp
@@ -132,6 +132,13 @@ static glue* moreglue(int n) {
return g;
}
+static inline void free_fgetln_buffer(FILE* fp) {
+ if (__predict_false(fp->_lb._base != nullptr)) {
+ free(fp->_lb._base);
+ fp->_lb._base = nullptr;
+ }
+}
+
/*
* Find a free FILE for fopen et al.
*/
@@ -326,7 +333,7 @@ FILE* freopen(const char* file, const char* mode, FILE* fp) {
if (HASUB(fp)) FREEUB(fp);
_UB(fp)._size = 0;
WCIO_FREE(fp);
- if (HASLB(fp)) FREELB(fp);
+ free_fgetln_buffer(fp);
fp->_lb._size = 0;
if (fd < 0) { // Did not get it after all.
@@ -386,7 +393,7 @@ int fclose(FILE* fp) {
}
if (fp->_flags & __SMBF) free(fp->_bf._base);
if (HASUB(fp)) FREEUB(fp);
- if (HASLB(fp)) FREELB(fp);
+ free_fgetln_buffer(fp);
// Poison this FILE so accesses after fclose will be obvious.
fp->_file = -1;