fstd/libsrsirc

Return value after free()-ing it

Closed this issue · 1 comments

free(m);

free(m) then one line below is return m;

return m;

Return value is never used. Was NULL or true/false maybe intended to be here or is this on purpose?

(Found with cppcheck)

fstd commented

Hey, thanks for your report.

It looks a bit contrived but the logic checks out, I think. The idea is to have the function return whether or not something was dropped, and m (after the implicit conversion to bool) does that, since m will be non-NULL in that case (and we're making use of the fact that free(NULL) is explicitly permitted here.

I agree it looks like a potential use-after-free though, and the return should probably read return !!m instead, for clarity.

You're right about the value eventually not being used though -- turns out we don't really need it in the places it's used (essentially the PART and the KICK handlers). Can't hurt to have the mechanism, though.

Thanks again for the input!