summaryrefslogtreecommitdiffstats
path: root/core/jni
diff options
context:
space:
mode:
authorDave Burke <daveburke@google.com>2014-09-26 19:33:26 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-09-26 19:33:27 +0000
commit6bf7be3b752bb3e8a10278136b8d2c0e57a731d9 (patch)
treec2f391191102c5fae613758f80ec4d3f860c7231 /core/jni
parent22ef3ed3055ff668089853bd6e1e685a2e4cef45 (diff)
parentd29c902f9822ab4b11dd4b91729c64d6987cdf29 (diff)
downloadframeworks_base-6bf7be3b752bb3e8a10278136b8d2c0e57a731d9.zip
frameworks_base-6bf7be3b752bb3e8a10278136b8d2c0e57a731d9.tar.gz
frameworks_base-6bf7be3b752bb3e8a10278136b8d2c0e57a731d9.tar.bz2
Merge "Revert "Fix memory leak where we close the descriptor instead of the file."" into lmp-dev
Diffstat (limited to 'core/jni')
-rw-r--r--core/jni/android/graphics/BitmapFactory.cpp16
1 files changed, 5 insertions, 11 deletions
diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp
index 6796134..8ea28ec 100644
--- a/core/jni/android/graphics/BitmapFactory.cpp
+++ b/core/jni/android/graphics/BitmapFactory.cpp
@@ -478,7 +478,7 @@ static jobject nativeDecodeFileDescriptor(JNIEnv* env, jobject clazz, jobject fi
NPE_CHECK_RETURN_ZERO(env, fileDescriptor);
- int descriptor = jniGetFDFromFileDescriptor(env, fileDescriptor);
+ jint descriptor = jniGetFDFromFileDescriptor(env, fileDescriptor);
struct stat fdStat;
if (fstat(descriptor, &fdStat) == -1) {
@@ -486,22 +486,16 @@ static jobject nativeDecodeFileDescriptor(JNIEnv* env, jobject clazz, jobject fi
return nullObjectReturn("fstat return -1");
}
- // Duplicate the descriptor here to prevent leaking memory. A leak occurs
- // if we only close the file descriptor and not the file object it is used to
- // create. If we don't explicitly clean up the file (which in turn closes the
- // descriptor) the buffers allocated internally by fseek will be leaked.
- int dupDescriptor = dup(descriptor);
+ // Restore the descriptor's offset on exiting this function.
+ AutoFDSeek autoRestore(descriptor);
- FILE* file = fdopen(dupDescriptor, "r");
+ FILE* file = fdopen(descriptor, "r");
if (file == NULL) {
- // cleanup the duplicated descriptor since it will not be closed when the
- // file is cleaned up (fclose).
- close(dupDescriptor);
return nullObjectReturn("Could not open file");
}
SkAutoTUnref<SkFILEStream> fileStream(new SkFILEStream(file,
- SkFILEStream::kCallerPasses_Ownership));
+ SkFILEStream::kCallerRetains_Ownership));
// Use a buffered stream. Although an SkFILEStream can be rewound, this
// ensures that SkImageDecoder::Factory never rewinds beyond the