Skip to content

Commit 484e610

Browse files
author
Father Chrysostomos
committed
Use shared memory for sv_debug_file
With -DDEBUGGING -Accflags=-DDEBUG_LEAKING_SCALARS -Duseithreads: use threads; use threads::shared; my @shared_ary :shared; $shared_ary[0] = &threads::shared::share({}); @shared_ary = (); __END__ panic: free from wrong pool, 881c00!=800000. Scalars leaked: 1 threads::shared has to juggle multiple interpreters. Sometimes the interpreter it is calling into (and passing as the first argument via pTHX) is not actually the current thread as far as the OS is concerned. Perl_safesysfree in util.c does not take a pTHX parameter, so it fetches the current interpreter from the data associated with the cur- rent thread. The result is that PERL_TRACK_MEMPOOL complains that the file name associated with an SV under DEBUG_LEAKING_SCALARS is being freed from the wrong interpreter. Using shared memory for the file name solves the issue.
1 parent 1e5f02b commit 484e610

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

sv.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ Public API:
182182
#endif
183183

184184
#ifdef DEBUG_LEAKING_SCALARS
185-
# define FREE_SV_DEBUG_FILE(sv) Safefree((sv)->sv_debug_file)
185+
# define FREE_SV_DEBUG_FILE(sv) STMT_START { \
186+
if ((sv)->sv_debug_file) PerlMemShared_free((sv)->sv_debug_file); \
187+
} STMT_END
186188
# define DEBUG_SV_SERIAL(sv) \
187189
DEBUG_m(PerlIO_printf(Perl_debug_log, "0x%"UVxf": (%05ld) del_SV\n", \
188190
PTR2UV(sv), (long)(sv)->sv_debug_serial))
@@ -275,7 +277,7 @@ S_new_SV(pTHX_ const char *file, int line, const char *func)
275277
);
276278
sv->sv_debug_inpad = 0;
277279
sv->sv_debug_parent = NULL;
278-
sv->sv_debug_file = PL_curcop ? savepv(CopFILE(PL_curcop)): NULL;
280+
sv->sv_debug_file = PL_curcop ? savesharedpv(CopFILE(PL_curcop)): NULL;
279281

280282
sv->sv_debug_serial = PL_sv_serial++;
281283

@@ -11905,7 +11907,7 @@ S_sv_dup_common(pTHX_ const SV *const sstr, CLONE_PARAMS *const param)
1190511907
dstr->sv_debug_inpad = sstr->sv_debug_inpad;
1190611908
dstr->sv_debug_parent = (SV*)sstr;
1190711909
FREE_SV_DEBUG_FILE(dstr);
11908-
dstr->sv_debug_file = savepv(sstr->sv_debug_file);
11910+
dstr->sv_debug_file = savesharedpv(sstr->sv_debug_file);
1190911911
#endif
1191011912

1191111913
ptr_table_store(PL_ptr_table, sstr, dstr);

0 commit comments

Comments
 (0)