Loading core/jni/android_database_SQLiteConnection.cpp +2 −3 Original line number Diff line number Diff line Loading @@ -671,9 +671,8 @@ static int createAshmemRegionWithData(JNIEnv* env, const void* data, size_t leng ALOGE("ashmem_create_region failed: %s", strerror(error)); } else { if (length > 0) { std::unique_ptr<base::MappedFile> mappedFile = base::MappedFile::FromFd(fd, 0, length, PROT_READ | PROT_WRITE); if (mappedFile == nullptr) { auto mappedFile = base::MappedFile::Create(fd, 0, length, PROT_READ | PROT_WRITE); if (!mappedFile) { error = errno; ALOGE("mmap failed: %s", strerror(error)); } else { Loading core/jni/android_text_Hyphenator.cpp +4 −3 Original line number Diff line number Diff line Loading @@ -70,12 +70,13 @@ static std::pair<const uint8_t*, size_t> mmapPatternFile(const std::string& loca return std::make_pair(nullptr, 0); } #else std::unique_ptr<base::MappedFile> patternFile = base::MappedFile::FromFd(fd, 0, st.st_size, PROT_READ); auto patternFile = base::MappedFile::Create(fd, 0, st.st_size, PROT_READ); close(fd); if (patternFile == nullptr) { if (!patternFile) { return std::make_pair(nullptr, 0); } // Yes, this line leaks the allocated MappedFile object, because it needs to load the file // for the lifetime of the process and MappedFile doesn't have a way to "release" the mapping. auto* mappedPtr = new base::MappedFile(std::move(*patternFile)); char* ptr = mappedPtr->data(); #endif Loading libs/androidfw/CursorWindow.cpp +5 −6 Original line number Diff line number Diff line Loading @@ -76,7 +76,7 @@ fail_silent: status_t CursorWindow::maybeInflate() { int ashmemFd = 0; void* newData = nullptr; std::unique_ptr<MappedFile> newMappedFile = nullptr; std::optional<MappedFile> newMappedFile; // Bail early when we can't expand any further if (mReadOnly || mSize == mInflatedSize) { Loading @@ -97,8 +97,8 @@ status_t CursorWindow::maybeInflate() { goto fail_silent; } newMappedFile = MappedFile::FromFd(ashmemFd, 0, mInflatedSize, PROT_READ | PROT_WRITE); if (newMappedFile == nullptr) { newMappedFile = MappedFile::Create(ashmemFd, 0, mInflatedSize, PROT_READ | PROT_WRITE); if (!newMappedFile) { PLOG(ERROR) << "Failed mmap"; goto fail_silent; } Loading Loading @@ -134,7 +134,6 @@ status_t CursorWindow::maybeInflate() { fail: LOG(ERROR) << "Failed maybeInflate"; fail_silent: newMappedFile.reset(); ::close(ashmemFd); return UNKNOWN_ERROR; } Loading Loading @@ -171,8 +170,8 @@ status_t CursorWindow::createFromParcel(Parcel* parcel, CursorWindow** outWindow PLOG(ERROR) << "Failed F_DUPFD_CLOEXEC"; goto fail_silent; } window->mMappedFile = MappedFile::FromFd(tempFd, 0, window->mSize, PROT_READ); if (window->mMappedFile == nullptr) { window->mMappedFile = MappedFile::Create(tempFd, 0, window->mSize, PROT_READ); if (!window->mMappedFile) { ::close(tempFd); PLOG(ERROR) << "Failed mmap"; goto fail_silent; Loading libs/androidfw/include/androidfw/CursorWindow.h +1 −1 Original line number Diff line number Diff line Loading @@ -152,8 +152,8 @@ public: private: String8 mName; std::optional<android::base::MappedFile> mMappedFile; int mAshmemFd = -1; std::unique_ptr<android::base::MappedFile> mMappedFile = nullptr; void* mData = nullptr; /** * Pointer to the first FieldSlot, used to optimize the extremely Loading Loading
core/jni/android_database_SQLiteConnection.cpp +2 −3 Original line number Diff line number Diff line Loading @@ -671,9 +671,8 @@ static int createAshmemRegionWithData(JNIEnv* env, const void* data, size_t leng ALOGE("ashmem_create_region failed: %s", strerror(error)); } else { if (length > 0) { std::unique_ptr<base::MappedFile> mappedFile = base::MappedFile::FromFd(fd, 0, length, PROT_READ | PROT_WRITE); if (mappedFile == nullptr) { auto mappedFile = base::MappedFile::Create(fd, 0, length, PROT_READ | PROT_WRITE); if (!mappedFile) { error = errno; ALOGE("mmap failed: %s", strerror(error)); } else { Loading
core/jni/android_text_Hyphenator.cpp +4 −3 Original line number Diff line number Diff line Loading @@ -70,12 +70,13 @@ static std::pair<const uint8_t*, size_t> mmapPatternFile(const std::string& loca return std::make_pair(nullptr, 0); } #else std::unique_ptr<base::MappedFile> patternFile = base::MappedFile::FromFd(fd, 0, st.st_size, PROT_READ); auto patternFile = base::MappedFile::Create(fd, 0, st.st_size, PROT_READ); close(fd); if (patternFile == nullptr) { if (!patternFile) { return std::make_pair(nullptr, 0); } // Yes, this line leaks the allocated MappedFile object, because it needs to load the file // for the lifetime of the process and MappedFile doesn't have a way to "release" the mapping. auto* mappedPtr = new base::MappedFile(std::move(*patternFile)); char* ptr = mappedPtr->data(); #endif Loading
libs/androidfw/CursorWindow.cpp +5 −6 Original line number Diff line number Diff line Loading @@ -76,7 +76,7 @@ fail_silent: status_t CursorWindow::maybeInflate() { int ashmemFd = 0; void* newData = nullptr; std::unique_ptr<MappedFile> newMappedFile = nullptr; std::optional<MappedFile> newMappedFile; // Bail early when we can't expand any further if (mReadOnly || mSize == mInflatedSize) { Loading @@ -97,8 +97,8 @@ status_t CursorWindow::maybeInflate() { goto fail_silent; } newMappedFile = MappedFile::FromFd(ashmemFd, 0, mInflatedSize, PROT_READ | PROT_WRITE); if (newMappedFile == nullptr) { newMappedFile = MappedFile::Create(ashmemFd, 0, mInflatedSize, PROT_READ | PROT_WRITE); if (!newMappedFile) { PLOG(ERROR) << "Failed mmap"; goto fail_silent; } Loading Loading @@ -134,7 +134,6 @@ status_t CursorWindow::maybeInflate() { fail: LOG(ERROR) << "Failed maybeInflate"; fail_silent: newMappedFile.reset(); ::close(ashmemFd); return UNKNOWN_ERROR; } Loading Loading @@ -171,8 +170,8 @@ status_t CursorWindow::createFromParcel(Parcel* parcel, CursorWindow** outWindow PLOG(ERROR) << "Failed F_DUPFD_CLOEXEC"; goto fail_silent; } window->mMappedFile = MappedFile::FromFd(tempFd, 0, window->mSize, PROT_READ); if (window->mMappedFile == nullptr) { window->mMappedFile = MappedFile::Create(tempFd, 0, window->mSize, PROT_READ); if (!window->mMappedFile) { ::close(tempFd); PLOG(ERROR) << "Failed mmap"; goto fail_silent; Loading
libs/androidfw/include/androidfw/CursorWindow.h +1 −1 Original line number Diff line number Diff line Loading @@ -152,8 +152,8 @@ public: private: String8 mName; std::optional<android::base::MappedFile> mMappedFile; int mAshmemFd = -1; std::unique_ptr<android::base::MappedFile> mMappedFile = nullptr; void* mData = nullptr; /** * Pointer to the first FieldSlot, used to optimize the extremely Loading