-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't free uninitialized local variables. #2
Don't free uninitialized local variables. #2
Conversation
Jumping over the declaration of a local variable that has a destructor doesn't work since the variable will be uninitialized when the destructor runs.
This sorta thing is why I'm not a big fan of these automatic gcc destructors in C code. |
I guess one just can't use it with C99 style declarations, but it's worked really well in my other codebases, and systemd uses it extensively. I don't feel like C99 declarations are that big of a win anyways, I tend to just stick to C89. |
Yeah, perhaps. But it's such a shame that dtor stuff is negated by our out: style of function returns, and the fact that you have to carefully assign, initialize, track the values assigned to the dtor'd variables anyway. It doesn't really end up reducing the amount of code in so many of our use cases. |
Of the three conflicting things (goto out, interleaved declarations, destructors), my least favourite is "goto out". If we manage to replace all of those with just "return", we should be good. This probably means we need to define destructors for more types than what libgsystem offers right now. |
Jumping over the declaration of a local variable that has a destructor
doesn't work since the variable will be uninitialized when the
destructor runs.