Skip to content
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

Merged
merged 1 commit into from
Nov 1, 2013

Conversation

mvollmer
Copy link
Member

@mvollmer mvollmer commented Nov 1, 2013

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.

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.
@puiterwijk puiterwijk merged commit dc49d37 into master Nov 1, 2013
@puiterwijk puiterwijk deleted the wip/avoid-unitialized-vars-with-gs-local-alloc branch November 1, 2013 20:46
@stefwalter
Copy link
Contributor

This sorta thing is why I'm not a big fan of these automatic gcc destructors in C code.

@cgwalters
Copy link
Contributor

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.

@stefwalter
Copy link
Contributor

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.

@mvollmer
Copy link
Member Author

mvollmer commented Nov 4, 2013

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.

garrett referenced this pull request in garrett/cockpit Jun 4, 2018
martinpitt added a commit that referenced this pull request Apr 6, 2020
Commit e93698e fixed testNotifyFailed(). Fix testHiddenFailure() in
the same way, so that a failure to load available updates does not get
in the way.

Closes #13849
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants