On Wed, Dec 18, 2013 at 3:16 AM, Calle Dybedahl <ca...@cyberpomo.com> wrote:
> Hi.
>
> The perlapi manpage has this to say about Safefree():
>
>    The XSUB-writer's interface to the C "free" function.
>
> So I've been using it instead of a plain free() pretty consistently, and
> everything seemed to work just fine. Until I uploaded my module to CPAN,
> and it started getting tested on operating systems that I normally don't
> run. In particular, OpenBSD. Where my code started dumping core. After
> bringing up an OpenBSD VM and experimenting for some time, I've found
> that replacing Safefree() with a plain free() makes the coredumps stop.
>
> Obviously, I have missed something. My current hypothesis is that the
> problem was that I used Safefree() on memory that wasn't allocated by
> one of the corresponding [mc]alloc() wrappers, but instead returned by a
> third-party library function. I haven't yet tried to dig into the perl
> source code to see if this is the case, but I haven't found anything
> about it in the documentation. Is there some place I've missed? Are
> there other functions I should also be wary about using?
>

The documentation doesn't quite make this clear, but Safefree should
only be used on memory obtained by other perlapi calls like Newx().

It's possible the reason it wasn't crashing on your machine is that
your Perl is configured to use malloc/free instead of Perl's own
allocator.

You can figure that out by checking perl -V for usemymalloc.

If it's "=n", Perl is using whatever native calls are available on your system.

If it's "=y", Perl is using its own internal wrapper.

Cheers,

-- Matthew Horsfall (alh)

Reply via email to