summaryrefslogtreecommitdiffhomepage
path: root/dev/LibCompiler
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-04-14 15:37:03 +0200
committerAmlal El Mahrouss <amlal@nekernel.org>2025-04-14 15:39:08 +0200
commit031582205502763a54d867e88dd4c83b3ae4eec7 (patch)
treeb7a77f62b625906761bef1f050ddc0f1f10e4e03 /dev/LibCompiler
parent6a348bd8899d3c00f4ac13becef91872fcbe8072 (diff)
ld64: fix memory leak in AE record allocation
Corrected allocation/deallocation of raw_ae_records when reading AE headers. This prevents memory leaks and ensures consistent cleanup before further processing. Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/LibCompiler')
-rw-r--r--dev/LibCompiler/src/DynamicLinkerPEF.cc17
1 files changed, 14 insertions, 3 deletions
diff --git a/dev/LibCompiler/src/DynamicLinkerPEF.cc b/dev/LibCompiler/src/DynamicLinkerPEF.cc
index 0a47b88..97f6d04 100644
--- a/dev/LibCompiler/src/DynamicLinkerPEF.cc
+++ b/dev/LibCompiler/src/DynamicLinkerPEF.cc
@@ -39,7 +39,9 @@
#define kPefNoCpu 0U
#define kPefNoSubCpu 0U
-#define kStdOut (std::cout << "\e[0;31m" << "ld64: " << "\e[0;97m")
+#define kStdOut (std::cout << "\e[0;31m" \
+ << "ld64: " \
+ << "\e[0;97m")
#define kLinkerDefaultOrigin kPefBaseOrigin
#define kLinkerId (0x5046FF)
@@ -333,6 +335,12 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF)
char_type* raw_ae_records =
new char_type[cnt * sizeof(LibCompiler::AERecordHeader)];
+ if (!raw_ae_records)
+ {
+ if (kVerbose)
+ kStdOut << "allocation failure for records of n: " << cnt << "\n";
+ }
+
memset(raw_ae_records, 0, cnt * sizeof(LibCompiler::AERecordHeader));
auto* ae_records = reader_protocol.Read(raw_ae_records, cnt);
@@ -399,6 +407,7 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF)
}
delete[] raw_ae_records;
+ raw_ae_records = nullptr;
std::vector<char> bytes;
bytes.resize(ae_header.fCodeSize);
@@ -520,7 +529,7 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF)
{
if (kVerbose)
kStdOut
- << "undefined entrypoint: " << kPefStart << ", you may have forget to ld64 "
+ << "undefined entrypoint: " << kPefStart << ", you may have forget to link "
"against your compiler's runtime library.\n";
kStdOut << "undefined entrypoint " << kPefStart
@@ -717,7 +726,7 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF)
{
for (auto& symbol : dupl_symbols)
{
- kStdOut << "Multiple symbols of " << symbol << ".\n";
+ kStdOut << "Multiple symbols of: " << symbol << " detected, cannot continue.\n";
}
return LIBCOMPILER_EXEC_ERROR;
@@ -753,6 +762,8 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF)
{
kStdOut << "undefined symbol " << unreferenced_symbol << "\n";
}
+
+ return LIBCOMPILER_EXEC_ERROR;
}
if (!kStartFound || kDuplicateSymbols && std::filesystem::exists(kOutput) ||