Skip to content

Commit f8a98ac

Browse files
authored
use kore_alloc_always_gc instead of malloc when building config (#1178)
Making this change prevents a memory leak because `free` was never being called previously on this memory.
1 parent dfcadbe commit f8a98ac

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/codegen/EmitConfigParser.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ static std::pair<llvm::Value *, llvm::BasicBlock *> get_eval(
389389
auto *malloc = create_malloc(
390390
creator.get_current_block(),
391391
llvm::ConstantExpr::getSizeOf(result->getType()),
392-
get_or_insert_function(mod, "malloc", ptr_ty, ptr_ty));
392+
get_or_insert_function(mod, "kore_alloc_always_gc", ptr_ty, ptr_ty));
393393
new llvm::StoreInst(result, malloc, creator.get_current_block());
394394
retval = malloc;
395395
break;
@@ -563,7 +563,8 @@ static void emit_get_token(kore_definition *definition, llvm::Module *module) {
563563
case_block);
564564
auto *malloc = create_malloc(
565565
case_block, llvm::ConstantExpr::getSizeOf(compare->getType()),
566-
get_or_insert_function(module, "malloc", ptr_ty, ptr_ty));
566+
get_or_insert_function(
567+
module, "kore_alloc_always_gc", ptr_ty, ptr_ty));
567568
new llvm::StoreInst(compare, malloc, case_block);
568569
phi->addIncoming(malloc, case_block);
569570
llvm::BranchInst::Create(merge_block, case_block);

runtime/util/ConfigurationParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void *get_mint_token(size_t size, char const *c_str) {
2929
std::string precision_str = str.substr(idx + 1);
3030
long long precision = std::stoll(precision_str);
3131
long long precision_in_bytes = (precision + 7) / 8;
32-
char *token = (char *)malloc(precision_in_bytes);
32+
char *token = (char *)kore_alloc_always_gc(precision_in_bytes);
3333
std::string val_str = str.substr(0, idx);
3434
mpz_t z;
3535
mpz_init_set_str(z, val_str.c_str(), 10);

0 commit comments

Comments
 (0)