Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I have a perl source code filter module, written in XS/C, which contains a BOOT: section that allocates some memory using Newz() and an END subroutine that frees it using Safefree().

This works fine in "normal usage", and under CGI, but under mod_perl it breaks because the BOOT: is only run once but the END is run at the end of each request (since the filter module is necessarily pulled in during the loading of the script to be filtered, rather than preloaded via PerlModule during the server startup). Hence multiple requests end up multiply repeatedly free()'ing space that has long since already been free()'d at the end of the first request. Not good.

The question is: What can I do to solve this? Ideally I would like a solution that will work within the filter module itself, rather than requiring the users of the module to do extra stuff, and it must also work in non-mod_perl usage too.

The simplest solution is to just delete the END subroutine. The space allocated in BOOT: will get returned to the OS when the process exits anyway, so do I even need to be free()'ing it explicitly?

Can anyone see any problem with not bothering to do the free()'s at all?

Is there another solution besides just omitting the END sub? I couldn't see any counterpart to BOOT: in the perlxs manpage, and DESTROY is no good since it is only called for objects, not packages/classes.

- Steve


In reply to Do I need to free allocated space in an END sub? by shay

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (4)
    As of 2020-08-04 03:24 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Which rocket would you take to Mars?










      Results (31 votes). Check out past polls.

      Notices?