On 2004-01-01, at 18:29:16 +0000, [EMAIL PROTECTED] wrote:
> On Thu, Jan 01, 2004 at 07:17:24PM +0100, Marcus Holland-Moritz wrote:
> | On 2004-01-01, at 17:42:17 +0000, [EMAIL PROTECTED] wrote:
> |
> | > Second, I have a XS producing strings. Do I need to free them? I ask this
> | > because the scripts keeps increasing the memory used (although I'm not
> | > storing any information at all).
> |
> | What do you mean by "producing strings"?
> | Could you please show us the relevant parts of the XS code?
>
> Of course :)
>
> char*
> wlgetbyid(id, word)
> int id
> U32 word
> INIT:
> char* str;
> CODE:
> if (id > MAXDICS || id < 0 || !wln[id]) {
> str = g_strdup("");
> } else {
> str = word_list_get_by_id(wln[id], word);
> if (!str) str = g_strdup("(null)");
> }
> RETVAL = str;
> OUTPUT:
> RETVAL
>
> Here, str is "(null)" from the strdup or another string (returned by
> the word_list_get_by_id). Both of them must be freed.
You can simply add a CLEANUP section (see 'perldoc perlxs' and search
for CLEANUP) to your wlgetbyid() XSUB and free the memory allocated
by g_strdup():
CLEANUP:
free(str); /* or similar call to free the memory */
This should take care of your memory leakage.
--
Schmidt's Observation:
All things being equal, a fat person uses more soap
than a thin person.