diff options
author | Elliott Hughes <enh@google.com> | 2014-05-13 10:14:22 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2014-05-13 10:14:22 -0700 |
commit | b6943186ce78105155ba67ab261a970859b190df (patch) | |
tree | 403dca669bc6b0dfa478d50bb8dbe272bc4277b7 /libc/bionic | |
parent | 2b18b10710995834e955658aedad3fdb2f994af8 (diff) | |
download | bionic-b6943186ce78105155ba67ab261a970859b190df.zip bionic-b6943186ce78105155ba67ab261a970859b190df.tar.gz bionic-b6943186ce78105155ba67ab261a970859b190df.tar.bz2 |
Reduce stack usage of tmpfile(3).
Also ensure that none of our home-grown code uses more than 2KiB per frame.
Change-Id: I8987a17d72f4b7f082bb7fa25e137c8433664c14
Diffstat (limited to 'libc/bionic')
-rw-r--r-- | libc/bionic/tmpfile.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/libc/bionic/tmpfile.cpp b/libc/bionic/tmpfile.cpp index 8419ff5..602d407 100644 --- a/libc/bionic/tmpfile.cpp +++ b/libc/bionic/tmpfile.cpp @@ -57,22 +57,23 @@ class ScopedSignalBlocker { }; static FILE* __tmpfile_dir(const char* tmp_dir) { - char buf[PATH_MAX]; - int path_length = snprintf(buf, sizeof(buf), "%s/tmp.XXXXXXXXXX", tmp_dir); - if (path_length >= static_cast<int>(sizeof(buf))) { + char* path = NULL; + if (asprintf(&path, "%s/tmp.XXXXXXXXXX", tmp_dir) == -1) { return NULL; } int fd; { ScopedSignalBlocker ssb; - fd = mkstemp(buf); + fd = mkstemp(path); if (fd == -1) { + free(path); return NULL; } // Unlink the file now so that it's removed when closed. - unlink(buf); + unlink(path); + free(path); // Can we still use the file now it's unlinked? // File systems without hard link support won't have the usual Unix semantics. |