Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2021-12-08 23:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (36 votes). Check out past polls.

    Notices?