Skip to content

Commit

Permalink
Fix memory leak in onStmtInIntent future (#22753)
Browse files Browse the repository at this point in the history
This test can't use deinit because of the memory management issues
involving the ``in`` intent. Instead, track the pointers in a list and
free them manually at the end of the test.

Trivial, not reviewed.
  • Loading branch information
benharsh authored Jul 14, 2023
2 parents 52fbfa0 + 602fc6e commit 048e735
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions test/multilocale/bharshbarg/onStmtInIntent.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@
use CTypes;
use Types;
use Communication;
use List;

// TODO: once in-intents work properly, we shouldn't need this anymore.
var pointers : list((locale, c_ptr(int)));
proc alloc() {
var ret : c_ptr(int) = allocate(int, 1);
pointers.pushBack((here, ret));
return ret;
}

record R {
var x : c_ptr(int);
var home : locale;

proc init() {
this.complete();
this.x = allocate(int, 1);
this.x = alloc();
home = here;
set(42);
}

proc init=(other: R) {
this.complete();
this.x = allocate(int, 1);
this.x = alloc();
home = here;
set(other.get());
writeln("init=");
Expand Down Expand Up @@ -63,4 +72,6 @@ proc main() {
writeln("before: ", x);
foo(x);
writeln("after: ", x);

for (loc, ptr) in pointers do on loc do deallocate(ptr);
}

0 comments on commit 048e735

Please sign in to comment.