Merge "linker: Fix memory leak for reserved memory" am: f81ceb939e am: a64695952d

Original change: https://android-review.googlesource.com/c/platform/bionic/+/2370012

Change-Id: I61d37cd4dfb66ba75506b05b974bef1267538236
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Ryan Prichard 2023-01-05 22:07:19 +00:00 committed by Automerger Merge Worker
commit c7dc6c3fe1

View file

@ -175,7 +175,8 @@ bool ElfReader::Load(address_space_params* address_space) {
if (did_load_) {
return true;
}
if (ReserveAddressSpace(address_space) && LoadSegments() && FindPhdr() &&
bool reserveSuccess = ReserveAddressSpace(address_space);
if (reserveSuccess && LoadSegments() && FindPhdr() &&
FindGnuPropertySection()) {
did_load_ = true;
#if defined(__aarch64__)
@ -186,6 +187,13 @@ bool ElfReader::Load(address_space_params* address_space) {
}
#endif
}
if (reserveSuccess && !did_load_) {
if (load_start_ != nullptr && load_size_ != 0) {
if (!mapped_by_caller_) {
munmap(load_start_, load_size_);
}
}
}
return did_load_;
}