Skip to content

Release resources in error paths via cleanup#4402

Merged
Cyan4973 merged 4 commits into
facebook:devfrom
mugitya03:tests
Jun 21, 2025
Merged

Release resources in error paths via cleanup#4402
Cyan4973 merged 4 commits into
facebook:devfrom
mugitya03:tests

Conversation

@mugitya03

Copy link
Copy Markdown

Replace direct returns in error-handling branches with a unified cleanup block that frees allocated resources before returning, improving code quality and robustness.

Replace direct returns in error-handling branches with a unified
cleanup block that frees allocated resources before returning,
improving code quality and robustness.
@Cyan4973 Cyan4973 self-assigned this Jun 13, 2025
@Cyan4973

Cyan4973 commented Jun 13, 2025

Copy link
Copy Markdown
Contributor

Unfortunately, merge conflicts have emerged since the review.
Would you be able to fix them ?

Comment thread tests/bigdict.c Outdated
@@ -0,0 +1,132 @@
/*

@Cyan4973 Cyan4973 Jun 21, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file simply shouldn't exist anymore.
It's a duplicate.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I just deleted it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to squash these three commits locally, but it seems that squashing a merge commit is not straightforward.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to squash these three commits locally, but it seems that squashing a merge commit is not straightforward.

This can be done at merge time, via the github UI.

Comment thread tests/largeDictionary.c Outdated
int _exit_code = 1;
(void)argc;
(void)argv;
int _exit_code = 0;

@Cyan4973 Cyan4973 Jun 21, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int _exit_code = 1;
(...)
int _exit_code = 0;

Declaring the same variable twice ?
This feels like it shouldn't work ?
I'm surprised it even compiles.

Even if it does, it looks to me that this is not the wanted behavior: due to overloading, _exit_code value would always be 0.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, thanks for pointing that out. This was duplicated during the merge—I’ll remove the second declaration.

@Cyan4973 Cyan4973 Jun 21, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That being said, I still don't understand why CI did not turn red.
I would have expected this unit to fail compilation. But CI is green.
Which leaves use with a few options:

  • It can actually compile and is legal (which I doubted, so that would be new learning for me)
  • It fails, but the CI does not detect it and turns green anyway (bad)
  • The file is never compiled during CI (bad, should be fixed)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested locally:

largeDictionary.c:76:9: error: redefinition of '_exit_code'
   76 |     int _exit_code = 0;
      |         ^
largeDictionary.c:73:9: note: previous definition is here
   73 |     int _exit_code = 1;
      |         ^
largeDictionary.c:76:9: warning: mixing declarations and code is incompatible with standards before C99 [-Wdeclaration-after-statement]
   76 |     int _exit_code = 0;
      |         ^

Compilation fails as expected.
So we are left with the other 2 options.

@Cyan4973 Cyan4973 Jun 21, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I think it's a case of test not run in CI.
It seems to be a long test btw, maybe that's why it was not set in CI.

I think that a test that is not run in CI, and is just expected to be run manually from time to time,
loses a lot of its value.
If it's too long to run in CI, maybe it's worth making it shorter, or at least allow a shorter version to be run in CI.

This is somewhat separate from your PR, so you are not expected to act on this.
But it's also somewhat related too, since your changes in this PR are not captured by CI for the time being (hence errors remain invisible).

@Cyan4973

Copy link
Copy Markdown
Contributor

In #4416, I'm adding a test to CI, that should run this unit.

It is expected to fail, due to an existing warning.

It will be rebased on top of this PR once it's merged,
thus ensuring that this unit is tested in CI from now on.

@Cyan4973
Cyan4973 merged commit 528132e into facebook:dev Jun 21, 2025
103 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants