Skip to content

Commit

Permalink
Merge pull request #13656 from daviditen/array-as-vec-bug
Browse files Browse the repository at this point in the history
Fix array-as-vec bug

[reviewed and suggested by @ronawho]

When freeing an array-as-vec we were passing the size of the user-level array
instead of the size of the allocated array. This lead to a crash. Implement
@ronawho's fix (slightly modified) and add @LouisJenkinsCS's test to the test system.

Resolves #13611
  • Loading branch information
daviditen authored Aug 6, 2019
2 parents bf4a422 + 8ff49f1 commit 4243c0c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
10 changes: 8 additions & 2 deletions modules/internal/DefaultRectangular.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,7 @@ module DefaultRectangular {
chpl_call_free_func(externFreeFunc, c_ptrTo(data));
}
} else {
var freedData = false;
if dom.dsiNumIndices > 0 || dataAllocRange.length > 0 {
param needsDestroy = __primitive("needs auto destroy",
__primitive("deref", data[0]));
Expand All @@ -1073,10 +1074,15 @@ module DefaultRectangular {
if numElts == 0 then
numElts = dom.dsiNumIndices;
dsiDestroyDataHelper(data, numElts);
_ddata_free(data, numElts);
freedData = true;
}
}
const size = blk(1) * dom.dsiDim(1).length;
_ddata_free(data, size);
if !freedData {
const size = blk(1) * dom.dsiDim(1).length;
_ddata_free(data, size);
freedData = true;
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/runtime/configMatters/comm/bigArrayAsVec.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
config const n = 8*1024*1024;

var arr : [0..-1] int;
for i in 1..n {
arr.push_back(i);
}
Empty file.
1 change: 1 addition & 0 deletions test/runtime/configMatters/comm/bigArrayAsVec.numlocales
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2

0 comments on commit 4243c0c

Please sign in to comment.