summaryrefslogtreecommitdiffstats
path: root/libcutils
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-12-16 08:33:52 -0800
committerElliott Hughes <enh@google.com>2015-12-16 08:33:52 -0800
commit391809025289e39f8e0eda3da949ea717bf67397 (patch)
tree6cad0b5b08b4bea78a01773fc665c48a49c192c8 /libcutils
parent461a29540c01b44f07fc26ccb0d5bc7d0d92a974 (diff)
downloadcore-391809025289e39f8e0eda3da949ea717bf67397.tar.gz
core-391809025289e39f8e0eda3da949ea717bf67397.tar.bz2
core-391809025289e39f8e0eda3da949ea717bf67397.zip
Make host ashmem_create_region more robust.
Don't clobber errno if mkstemp failed, always unlink, and only count mkstemp/ftruncate failures as real failures --- if only the unlink fails, there's no point not using what we have. Change-Id: I6bc788682c88651a50a6316b9ca07ba07e9fefa2
Diffstat (limited to 'libcutils')
-rw-r--r--libcutils/ashmem-host.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/libcutils/ashmem-host.c b/libcutils/ashmem-host.c
index abc4f9474..15dd43edb 100644
--- a/libcutils/ashmem-host.c
+++ b/libcutils/ashmem-host.c
@@ -43,11 +43,16 @@ int ashmem_create_region(const char *ignored __unused, size_t size)
char template[PATH_MAX];
snprintf(template, sizeof(template), "/tmp/android-ashmem-%d-XXXXXXXXX", getpid());
int fd = mkstemp(template);
- if (fd != -1 && TEMP_FAILURE_RETRY(ftruncate(fd, size)) != -1 && unlink(template) != -1) {
- return fd;
+ if (fd == -1) return -1;
+
+ unlink(template);
+
+ if (TEMP_FAILURE_RETRY(ftruncate(fd, size)) == -1) {
+ close(fd);
+ return -1;
}
- close(fd);
- return -1;
+
+ return fd;
}
int ashmem_set_prot_region(int fd __unused, int prot __unused)