diff options
author | Leon Scroggins III <scroggo@google.com> | 2015-01-22 19:59:09 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-01-22 19:59:09 +0000 |
commit | 1dae686531927208eca3dc4f99e117ff28aeba97 (patch) | |
tree | 034afcc58a2cdd74d75970164a7a75cbeb0ce38f | |
parent | 4c8e0b762644e9189b035c7f4a541ba8d0ed262c (diff) | |
parent | a9ccf6f358d544eedc9432ca81da3d3c76b0e65a (diff) | |
download | jpeg-1dae686531927208eca3dc4f99e117ff28aeba97.tar.gz |
am a9ccf6f3: Fix bugs in jmem-ashmem.android-wear-5.1.1_r1android-wear-5.1.0_r1android-m-preview-2android-m-preview-1android-m-previewmaster-soong
* commit 'a9ccf6f358d544eedc9432ca81da3d3c76b0e65a':
Fix bugs in jmem-ashmem.
-rw-r--r-- | jmem-ashmem.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/jmem-ashmem.c b/jmem-ashmem.c index 3a17b02..0c35715 100644 --- a/jmem-ashmem.c +++ b/jmem-ashmem.c @@ -121,6 +121,8 @@ 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) { @@ -128,9 +130,16 @@ get_ashmem(backing_store_ptr info, long total_bytes_needed) } 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; |