summaryrefslogtreecommitdiff
path: root/libutils/FileMap.cpp
diff options
context:
space:
mode:
authorRenaud Paquay <rpaquay@google.com>2017-05-10 17:48:59 -0700
committerElliott Hughes <enh@google.com>2017-05-11 10:30:52 -0700
commitb7a4f0b9e2779fbddc675641c5a2978168f0df2f (patch)
tree30449eeb15a2b8b7387945c1f2eee6e2eca99976 /libutils/FileMap.cpp
parent44f6592b0de532afeb3636afb5177fd39b2442ea (diff)
Fix uninitialized member variable
The default constructor of FileMap was missing an initializer for the mFileMapping variables. This results in CloseHandle being called with a "random" value, which can cause havoc in Win32 process over time (e.g. in the case of libaapt2_jni.dll, which is loaded in a JVM process). Also, update the code to use "NULL" for invalid file map handle and "INVALID_HANDLE_VALUE" for invalid file handle. Bug: 38197857 Test: Stress testing on (Windows) machine Change-Id: Ibd769219d601fbafcfcee89e848b31cc5137826c
Diffstat (limited to 'libutils/FileMap.cpp')
-rw-r--r--libutils/FileMap.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/libutils/FileMap.cpp b/libutils/FileMap.cpp
index 1afa1ecae..3c4d81c1e 100644
--- a/libutils/FileMap.cpp
+++ b/libutils/FileMap.cpp
@@ -48,8 +48,16 @@ using namespace android;
// Constructor. Create an empty object.
FileMap::FileMap(void)
- : mFileName(NULL), mBasePtr(NULL), mBaseLength(0),
- mDataPtr(NULL), mDataLength(0)
+ : mFileName(NULL),
+ mBasePtr(NULL),
+ mBaseLength(0),
+ mDataPtr(NULL),
+ mDataLength(0)
+#if defined(__MINGW32__)
+ ,
+ mFileHandle(INVALID_HANDLE_VALUE),
+ mFileMapping(NULL)
+#endif
{
}
@@ -65,8 +73,8 @@ FileMap::FileMap(FileMap&& other)
other.mBasePtr = NULL;
other.mDataPtr = NULL;
#if defined(__MINGW32__)
- other.mFileHandle = 0;
- other.mFileMapping = 0;
+ other.mFileHandle = INVALID_HANDLE_VALUE;
+ other.mFileMapping = NULL;
#endif
}
@@ -84,8 +92,8 @@ FileMap& FileMap::operator=(FileMap&& other) {
#if defined(__MINGW32__)
mFileHandle = other.mFileHandle;
mFileMapping = other.mFileMapping;
- other.mFileHandle = 0;
- other.mFileMapping = 0;
+ other.mFileHandle = INVALID_HANDLE_VALUE;
+ other.mFileMapping = NULL;
#endif
return *this;
}
@@ -101,7 +109,7 @@ FileMap::~FileMap(void)
ALOGD("UnmapViewOfFile(%p) failed, error = %lu\n", mBasePtr,
GetLastError() );
}
- if (mFileMapping != INVALID_HANDLE_VALUE) {
+ if (mFileMapping != NULL) {
CloseHandle(mFileMapping);
}
#else
@@ -156,7 +164,7 @@ bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t le
ALOGE("MapViewOfFile(%" PRId64 ", %zu) failed with error %lu\n",
adjOffset, adjLength, GetLastError() );
CloseHandle(mFileMapping);
- mFileMapping = INVALID_HANDLE_VALUE;
+ mFileMapping = NULL;
return false;
}
#else // !defined(__MINGW32__)