am dbcba8f5
: Merge "Reduce stack usage of tmpfile(3)."
* commit 'dbcba8f5f9a59fac3d22dfc17a14d3d5cfb4f4b0': Reduce stack usage of tmpfile(3).
This commit is contained in:
commit
2b5503b578
@ -725,7 +725,10 @@ include $(BUILD_STATIC_LIBRARY)
|
|||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
LOCAL_SRC_FILES := $(libc_bionic_src_files)
|
LOCAL_SRC_FILES := $(libc_bionic_src_files)
|
||||||
LOCAL_CFLAGS := $(libc_common_cflags) -Werror
|
LOCAL_CFLAGS := $(libc_common_cflags) \
|
||||||
|
-Werror \
|
||||||
|
-Wframe-larger-than=2048 \
|
||||||
|
|
||||||
LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
|
LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
|
||||||
LOCAL_CPPFLAGS := $(libc_common_cppflags)
|
LOCAL_CPPFLAGS := $(libc_common_cppflags)
|
||||||
LOCAL_C_INCLUDES := $(libc_common_c_includes)
|
LOCAL_C_INCLUDES := $(libc_common_c_includes)
|
||||||
|
@ -57,22 +57,23 @@ class ScopedSignalBlocker {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static FILE* __tmpfile_dir(const char* tmp_dir) {
|
static FILE* __tmpfile_dir(const char* tmp_dir) {
|
||||||
char buf[PATH_MAX];
|
char* path = NULL;
|
||||||
int path_length = snprintf(buf, sizeof(buf), "%s/tmp.XXXXXXXXXX", tmp_dir);
|
if (asprintf(&path, "%s/tmp.XXXXXXXXXX", tmp_dir) == -1) {
|
||||||
if (path_length >= static_cast<int>(sizeof(buf))) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fd;
|
int fd;
|
||||||
{
|
{
|
||||||
ScopedSignalBlocker ssb;
|
ScopedSignalBlocker ssb;
|
||||||
fd = mkstemp(buf);
|
fd = mkstemp(path);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
|
free(path);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlink the file now so that it's removed when closed.
|
// 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?
|
// Can we still use the file now it's unlinked?
|
||||||
// File systems without hard link support won't have the usual Unix semantics.
|
// File systems without hard link support won't have the usual Unix semantics.
|
||||||
|
Loading…
Reference in New Issue
Block a user