diff options
author | Leon Scroggins III <scroggo@google.com> | 2015-01-15 16:56:41 -0500 |
---|---|---|
committer | Leon Scroggins <scroggo@google.com> | 2015-01-16 13:15:38 +0000 |
commit | a9ccf6f358d544eedc9432ca81da3d3c76b0e65a (patch) | |
tree | 871243893f826dc738275275559e8aab4b3f6d6c | |
parent | 021b9904279c7bcd08a66a349933fc883141db34 (diff) | |
download | jpeg-a9ccf6f358d544eedc9432ca81da3d3c76b0e65a.tar.gz |
Fix bugs in jmem-ashmem.android-cts-5.1_r9android-cts-5.1_r8android-cts-5.1_r7android-cts-5.1_r6android-cts-5.1_r5android-cts-5.1_r4android-cts-5.1_r3android-cts-5.1_r28android-cts-5.1_r27android-cts-5.1_r26android-cts-5.1_r25android-cts-5.1_r24android-cts-5.1_r23android-cts-5.1_r22android-cts-5.1_r21android-cts-5.1_r20android-cts-5.1_r2android-cts-5.1_r19android-cts-5.1_r18android-cts-5.1_r17android-cts-5.1_r16android-cts-5.1_r15android-cts-5.1_r14android-cts-5.1_r13android-cts-5.1_r10android-cts-5.1_r1android-5.1.1_r9android-5.1.1_r8android-5.1.1_r7android-5.1.1_r6android-5.1.1_r5android-5.1.1_r4android-5.1.1_r38android-5.1.1_r37android-5.1.1_r36android-5.1.1_r35android-5.1.1_r34android-5.1.1_r33android-5.1.1_r30android-5.1.1_r3android-5.1.1_r29android-5.1.1_r28android-5.1.1_r26android-5.1.1_r25android-5.1.1_r24android-5.1.1_r23android-5.1.1_r22android-5.1.1_r20android-5.1.1_r2android-5.1.1_r19android-5.1.1_r18android-5.1.1_r17android-5.1.1_r16android-5.1.1_r15android-5.1.1_r14android-5.1.1_r13android-5.1.1_r12android-5.1.1_r10android-5.1.1_r1android-5.1.0_r5android-5.1.0_r4android-5.1.0_r3android-5.1.0_r1lollipop-mr1-wfc-releaselollipop-mr1-releaselollipop-mr1-fi-releaselollipop-mr1-devlollipop-mr1-cts-release
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 3773c6ec2bcf603cfa2b16575022642b3e816297)
-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; |