Hello! I'm really starting to get the hang of the inline module, however,
I'm having a problem freeing memory. I've attempted to use SAFEFREEPV(),
but it causes my program to crash with a memory could not be "read" error.
Without using SAFEFREEPV(), there are no crashes, but the memory usage
skyrockets, I'm making about 30,000 calls to two functions, both of which
return a binary string of about 80 bytes (this goes up and down). Since I'm
returning the bulk of the memory, I call SAFEFREEPV() before my return()
statement, while this does seem a little off, but I can't think of any other
way to do it.
The rest of the functionality works out just fine, here are my offending
lines:
SV* function1 (int size) {
short *array;
int i;
/* have tried Newz() as well, with no difference in stopping the
crashing */
New(123, array, size, short);
for (i = 0; i <= size; i++) {
/* fill array with size data */
}
SAFEFREEPV(array);
return newSVpvn((char *)array, i * sizeof(short));
}
SV* combine (char * dat1, char * dat2, int size) {
short *array;
int i;
New(234, array, size, short);
for (i = 0; i <= size; i++) {
/* fill array with size data */
}
SAFEFREEPV(array);
return newSVpvn((char *)array, i);
}
The functions are called like:
my $outdat1 = function1(80);
my $comb_dat = combine($outdat1,$combined,80);
$combined = $comb_dat;
(I've tried just saying $combined = combine($outdat1,$combined,80); but
that seems to make no difference)
I've tried removing the SAFEFREEPV() macro, and using sv_2mortal() around
the return value, e.g.:
return sv_2mortal(newSVpvn((char *)array, i * sizeof(short)));
But this results in an "attempt to free unreferenced scalar" warning from
perl, and if the SAFEFREEPV() macro is kept in place, is followed by a
crash.
Is there any way to both free the memory being used by these functions and
not cause a crash?
Thanks!
!c
C. Church
http://www.digitalKOMA.com/church/
http://www.DroneColony.com/