Merge "Make host ashmem_create_region more robust."

This commit is contained in:
Elliott Hughes 2015-12-16 18:22:57 +00:00 committed by Gerrit Code Review
commit ec2f506e74
1 changed files with 9 additions and 4 deletions

View File

@ -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)