Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I'm guessing based on the C parts since I don't know XS very well.

    Aren't you calloc()ing a char buffer without free()ing it.

    John.
    --
    • Yes, but perl should free that when the SvREFCOUNT reaches zero.
      • Never mind, that does indeed appear to be the culprit. How strange - I could have sworn perl free'd the strings.
        • The string (ret) is copied from the svpv, and not maintained by any sv so it's not perl's responsibility to manage the memory allocated to it.
          • What's weird is this pretty much guarantees that a char * typemap will leak (as you can't free it before you return) unless you are returning static char *s.
            • The char* typemap uses newSVpv to turn the char* into an SV*. newSVpv copies the string into the scalar. Two options: use a CLEANUP section to free the string or use a custom typemap that frees the string.

              CLEANUP section: ...
                  CLEANUP:
                      free (ret);

              Custom typemap: in a typemap file:

              TYPEMAP
              char_own * T_CHAR_OWN
              OUTPUT
              T_CHAR_OWN
                              sv_setpv ((SV*)$arg, $var);
                              g_free ($var);

              And then use char_own* instead of char* for the type of the return value of the xsub.