Skip to content

Commit c34be29

Browse files
committed
Fix some issues regarding allocations within the sharedcache plugin FFI
1 parent 0f0801a commit c34be29

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

view/sharedcache/core/SharedCache.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3161,7 +3161,7 @@ extern "C"
31613161
auto value = cache->object->LoadAllSymbolsAndWait();
31623162
*count = value.size();
31633163

3164-
BNDSCSymbolRep* symbols = (BNDSCSymbolRep*)malloc(sizeof(BNDSCSymbolRep) * value.size());
3164+
BNDSCSymbolRep* symbols = new BNDSCSymbolRep[value.size()];
31653165
for (size_t i = 0; i < value.size(); i++)
31663166
{
31673167
symbols[i].address = value[i].second->GetAddress();
@@ -3227,7 +3227,7 @@ extern "C"
32273227
{
32283228
auto regions = cache->object->GetMappedRegions();
32293229
*count = regions.size();
3230-
BNDSCMappedMemoryRegion* mappedRegions = (BNDSCMappedMemoryRegion*)malloc(sizeof(BNDSCMappedMemoryRegion) * regions.size());
3230+
BNDSCMappedMemoryRegion* mappedRegions = new BNDSCMappedMemoryRegion[regions.size()];
32313231
for (size_t i = 0; i < regions.size(); i++)
32323232
{
32333233
mappedRegions[i].vmAddress = regions[i].start;
@@ -3258,14 +3258,14 @@ extern "C"
32583258
{
32593259
auto viewCaches = cache->object->BackingCaches();
32603260
*count = viewCaches.size();
3261-
caches = (BNDSCBackingCache*)malloc(sizeof(BNDSCBackingCache) * viewCaches.size());
3261+
caches = new BNDSCBackingCache[viewCaches.size()];
32623262
for (size_t i = 0; i < viewCaches.size(); i++)
32633263
{
32643264
caches[i].path = BNAllocString(viewCaches[i].path.c_str());
32653265
caches[i].isPrimary = viewCaches[i].isPrimary;
32663266

32673267
BNDSCBackingCacheMapping* mappings;
3268-
mappings = (BNDSCBackingCacheMapping*)malloc(sizeof(BNDSCBackingCacheMapping) * viewCaches[i].mappings.size());
3268+
mappings = new BNDSCBackingCacheMapping[viewCaches[i].mappings.size()];
32693269

32703270
size_t j = 0;
32713271
for (const auto& mapping : viewCaches[i].mappings)
@@ -3309,14 +3309,14 @@ extern "C"
33093309
auto vm = cache->object->GetVMMap(true);
33103310
auto viewImageHeaders = cache->object->AllImageHeaders();
33113311
*count = viewImageHeaders.size();
3312-
BNDSCImage* images = (BNDSCImage*)malloc(sizeof(BNDSCImage) * viewImageHeaders.size());
3312+
BNDSCImage* images = new BNDSCImage[viewImageHeaders.size()];
33133313
size_t i = 0;
33143314
for (const auto& [baseAddress, header] : viewImageHeaders)
33153315
{
33163316
images[i].name = BNAllocString(header.installName.c_str());
33173317
images[i].headerAddress = baseAddress;
33183318
images[i].mappingCount = header.sections.size();
3319-
images[i].mappings = (BNDSCImageMemoryMapping*)malloc(sizeof(BNDSCImageMemoryMapping) * header.sections.size());
3319+
images[i].mappings = new BNDSCImageMemoryMapping[header.sections.size()];
33203320
for (size_t j = 0; j < header.sections.size(); j++)
33213321
{
33223322
const auto sectionStart = header.sections[j].addr;

0 commit comments

Comments
 (0)