Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
Fix bugs in jmem-ashmem.
Browse files Browse the repository at this point in the history
If ashmem_set_prot_region fails, close the previously opened file.

If mmap fails, close the file and return -1.

BUG:18894965
Change-Id: I936b5c7395480249b1457e7dee566da6141fb023
(cherry picked from commit 3773c6e)
(cherry picked from commit a9ccf6f)
  • Loading branch information
LeonScroggins committed Feb 19, 2015
1 parent 135f5dc commit 0e1c7ef
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions jmem-ashmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,25 @@ LOCAL(int)
get_ashmem(backing_store_ptr info, long total_bytes_needed)
{
char path[1024];
// FIXME: Does this name need to be unique? What happens if two jpegs
// are being decoded simultaneously in the same process?
snprintf(path, 1023, "%d.tmp.ashmem", getpid());
int fd = ashmem_create_region(path, total_bytes_needed);
if (fd == -1) {
return -1;
}
int err = ashmem_set_prot_region(fd, PROT_READ | PROT_WRITE);
if (err) {
return -1;
close(fd);
return -1;
}
void* addr = mmap(NULL, total_bytes_needed, PROT_READ | PROT_WRITE,
MAP_PRIVATE, fd, 0);
if (-1 == (long) addr) {
close(fd);
return -1;
}
info->addr = mmap(NULL, total_bytes_needed, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
info->addr = addr;
info->size = total_bytes_needed;
info->temp_file = fd;
return fd;
Expand Down

0 comments on commit 0e1c7ef

Please sign in to comment.