Subject: | NYTProf fails with Carp |
Carp (in everything except blead) pulls weird tricks with delay-loading
in Carp::Heavy. This can cause CopFILE(PL_curcop) to be null, which
leads even the following simple snippet to segfault:
perl -d:NYTProf -e 'require Carp; Carp::longmess("whoops")'
Attached is a simplistic fix, and an appropriate test.
Subject: | 0001-Avoid-a-segfault-when-CopFILE-is-null-like-Carp-Heav.patch |
From 3fd12f48f7ee26ae3f42ef98ab727a8021a2eb89 Mon Sep 17 00:00:00 2001
From: Alex Vandiver <alex@chmrr.net>
Date: Thu, 5 Nov 2009 16:59:23 -0500
Subject: [PATCH] Avoid a segfault when CopFILE() is null, like Carp::Heavy causes
---
NYTProf.xs | 2 ++
t/test18-carp.p | 14 ++++++++++++++
t/test18-carp.t | 6 ++++++
3 files changed, 22 insertions(+), 0 deletions(-)
create mode 100644 t/test18-carp.p
create mode 100644 t/test18-carp.t
diff --git a/NYTProf.xs b/NYTProf.xs
index fa0f224..70b1245 100644
--- a/NYTProf.xs
+++ b/NYTProf.xs
@@ -2529,6 +2529,8 @@ subr_entry_setup(pTHX_ COP *prev_cop, subr_entry_t *clone_subr_entry, OPCODE op_
}
file = OutCopFILE(prev_cop);
+ if (file == NULL)
+ file = "(null)";
subr_entry->caller_fid = (file == last_executed_fileptr)
? last_executed_fid
: get_file_id(aTHX_ file, strlen(file), NYTP_FIDf_VIA_SUB);
diff --git a/t/test18-carp.p b/t/test18-carp.p
new file mode 100644
index 0000000..a0b2f8c
--- /dev/null
+++ b/t/test18-carp.p
@@ -0,0 +1,14 @@
+# Test Carp::Heavy's "swap subs out from under you with goto &sub"
+
+package Carp;
+
+sub longmess { goto &longmess_jmp }
+
+sub longmess_jmp {
+ local($@, $!);
+ eval { require Carp::Heavy };
+ return $@ if $@;
+ goto &longmess_real;
+}
+
+longmess("Oops");
diff --git a/t/test18-carp.t b/t/test18-carp.t
new file mode 100644
index 0000000..bbfeb78
--- /dev/null
+++ b/t/test18-carp.t
@@ -0,0 +1,6 @@
+use strict;
+use Test::More;
+use lib qw(t/lib);
+use NYTProfTest;
+
+run_test_group;
--
1.6.3.3.473.gb74fc4.dirty