Skip to content

Commit 0586f1a

Browse files
committed
Fix #19963, support Null pointer argument to jl_free
Null pointer argument must be allowed according to the standard (see C99, 7.20.2.3), in which case there should be no action.
1 parent 93ecb41 commit 0586f1a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-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)

0 commit comments

Comments
 (0)