When using the following in a module initialization function:
MAKE_CONSTANT_SHARED_STRING(a[i], "somestring");
the resulting string has a refcount of 2. if you then use
free_string(a[i]);
in the corresponding exit function, dmalloc reports a leak. when doing the same, but just on a pointer, rather than an array, dmalloc doesn't seem to care. Is this expected behavior? Is it an issue that the items aren't actually freed by free_string (because of the extra ref)? I'd imagine that it's probably not critical in this case, as we're talking about a module.
Bill
As I've said before (in 13893225), the MAKE_CONST_STRING variants make no sense in a module initialization function. They keep a cached copy of the string around to use the _next_ time the code is run (hence the extra ref), but the initialization function is only run once, so the _is_ no next time. So the extra ref, and the static variable to hold the cache, and the test so see if it was already initialized, are _all for nought_. Simply change
MAKE_CONSTANT_SHARED_STRING(a[i], "somestring");
to
a[i] = make_shared_binary_string("somestring", CONSTANT_STRLEN("somestring"));
and you'll get better code, and no trouble from dmalloc.
Thanks, Marcus... I must have tuned out for the conversation. This makes complete sense to me; sometimes it's hard to divine the intention of some of those macros.
Best,
Bill
On Thu, 2 Feb 2006, Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum wrote:
As I've said before (in 13893225), the MAKE_CONST_STRING variants make no sense in a module initialization function. They keep a cached copy of the string around to use the _next_ time the code is run (hence the extra ref), but the initialization function is only run once, so the _is_ no next time. So the extra ref, and the static variable to hold the cache, and the test so see if it was already initialized, are _all for nought_. Simply change
MAKE_CONSTANT_SHARED_STRING(a[i], "somestring");
to
a[i] = make_shared_binary_string("somestring", CONSTANT_STRLEN("somestring"));
and you'll get better code, and no trouble from dmalloc.
pike-devel@lists.lysator.liu.se