Skip to content

Commit 2ded6c4

Browse files
authored
Merge pull request #19969 from thofma/th/19963
Fix jl_free(NULL)
2 parents 93ecb41 + b820c05 commit 2ded6c4

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/gc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,9 +2088,11 @@ JL_DLLEXPORT void *jl_calloc(size_t nm, size_t sz)
20882088

20892089
JL_DLLEXPORT void jl_free(void *p)
20902090
{
2091-
int64_t *pp = (int64_t *)p - 2;
2092-
size_t sz = pp[0];
2093-
jl_gc_counted_free(pp, sz);
2091+
if (p != NULL) {
2092+
int64_t *pp = (int64_t *)p - 2;
2093+
size_t sz = pp[0];
2094+
jl_gc_counted_free(pp, sz);
2095+
}
20942096
}
20952097

20962098
JL_DLLEXPORT void *jl_realloc(void *p, size_t sz)

test/core.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4862,3 +4862,12 @@ end
48624862
@test_throws ErrorException isless(MyTime(1), now())
48634863

48644864
end
4865+
4866+
# issue #15240
4867+
4868+
p15240 = ccall(:jl_realloc, Ptr{Void}, (Ptr{Void}, Csize_t), C_NULL, 10)
4869+
ccall(:jl_free, Void, (Ptr{Void}, ), p15240)
4870+
4871+
# issue #19963
4872+
4873+
ccall(:jl_free, Void, (Ptr{Void}, ), C_NULL)

0 commit comments

Comments
 (0)