Subject: | memory anti-leak |
The .xs funtion smfi_setpriv makes this call:-
RETVAL = MI_BOOL_CVT(smfi_setpriv(ctx, (void *)newSVsv(data)));
which causes sendmail to "remember" the pointer to this new SV,
however, you have not told perl that sendmail is remembering this
pointer, so as soon as the perl calling subroutine is done with it's
setpriv() call, perl will "free" this new SV, because its reference
count returns to 0.
Additionally, the smfi_getpriv call grabs the pointer to this data,
and returns it to perl (thereby incrimenting the number of things
pointing to this scalar) without incrimenting the reference count
first, so as soon as whatever has used this value is finished with it,
perl will attempt to free this variable again (which will result in a
double-free, since setpriv probably already free it earlier).
this seems to be the cause of getpriv not working as expected
Eventually, this behaviour causes a segfault, probably whenever the
memory freed immediately after the setpriv gets re-used
I think the reason things are mostly working right now, is because
folks are blindly re-calling setpriv over and over, which slightly
lessens the fact that later calls to getpriv (which are returning
pointers to things that already got freed!) tend to seem to work,
since the stale memory they're using still (by luck) usually contains
a pointer to whatever they wanted.
If you agree that my interpretation is correct, I can send you the
patch which seems to fix this.