I have been able to work some more on RaSPF and the results are encouraging.
Thanks to valgrind and test suites, I am pretty confident it doesn't leak memory, or at least, that it doesn't leak except on very rare cases.
I think I found a neat way to simplify memory management, though, and that's what I wanted to mention.
This is probably trivial for everyone reading, but I am a limited C programmer, so whenever something works unexpectedly right, I am happy ;-)
One problem with C memory management is that if you have many exit points for your functions, releasing everything you allocate is rather annoying, since you may have
to do it in several different locations.
I compounded this problem because I am using exceptions (yeah, C doesn't have them. I used this).
Now not only do I have my returns but also my throws and whatever uncaught throw something I called has!
Nope: what exceptions complicated, exceptions fixed. Look at this function:
bstring spf_query_get_explanation(spf_query *q, bstring spec)
struct bstrList *l=0;
struct tagbstring s=bsStatic("");
// Expand an explanation
if (spec && spec->slen)
result=bfromcstr("explanation: Required option is missing");
It doesn't matter if spf_query_expand or spf_query_dns_txt throw an exception, this will not leak.
Nice, I think :-)