The XS needs to check that the variable is SvTYPE(var) == SVt_PV before it tries to unmap it.
This patch with tests should fix it.
diff --git a/Mmap.xs b/Mmap.xs
index 1c7b04b..c144a52 100644
--- a/Mmap.xs
+++ b/Mmap.xs
@@ -203,6 +203,11 @@ munmap(var)
CODE:
ST(0) = &PL_sv_undef;
/* XXX refrain from dumping core if this var wasnt previously mmap'd */
+ if(SvTYPE(var) != SVt_PV) {
+ croak("map pointer is not a stringundef");
+ return;
+ }
+
if (munmap((MMAP_RETTYPE) SvPVX(var) - SvLEN(var), SvCUR(var) + SvLEN(var)) == -1) {
croak("munmap failed! errno %d %s\n", errno, strerror(errno));
return;
diff --git a/t/munmap_errors.t b/t/munmap_errors.t
new file mode 100644
index 0000000..d250255
--- /dev/null
+++ b/t/munmap_errors.t
@@ -0,0 +1,19 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More tests => 2;
+
+use Sys::Mmap;
+
+{
+ my $foo;
+ eval {munmap($foo)};
+ like($@, qr/^map pointer is not a string/, "munmap detects undef strings");
+}
+
+{
+ my $foo = "";
+ eval {munmap($foo)};
+ is($@, "munmap failed! errno 22 Invalid argument\n", "Unmapped strings die");
+}