Skip to content

fix double fclose in aofrewrite#7919

Merged
oranagra merged 1 commit intoredis:unstablefrom
hwware:aof_double_fclose_fix
Oct 19, 2020
Merged

fix double fclose in aofrewrite#7919
oranagra merged 1 commit intoredis:unstablefrom
hwware:aof_double_fclose_fix

Conversation

@hwware
Copy link
Contributor

@hwware hwware commented Oct 16, 2020

Similar to #7307, in aof rewrite we also did double fclose, this PR fixed issue: #3834

@hwware hwware mentioned this pull request Oct 16, 2020
@hwware hwware force-pushed the aof_double_fclose_fix branch from d69615e to 668d897 Compare October 16, 2020 02:07
if (fclose(fp) == EOF) goto werr;
if (fflush(fp)) goto werr;
if (fsync(fileno(fp))) goto werr;
if (fclose(fp)) { fp = NULL; goto werr; }
Copy link
Contributor

Choose a reason for hiding this comment

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

I saw that Oran was okay with this in the previous CR, but it seems very inconsistent to have multiple statements on the same line.

Copy link
Member

Choose a reason for hiding this comment

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

I generally don't even like code statements that change the code flow (return, goto, break, continue, etc) being at the same line with the if.
However, when writing error handling code, I don't like it to consume too many lines and make it harder to read the actual code. So a boilerplate repatriation checking a condition and doing goto or return if each action fails, is ok with me to be on the same line with the action..

Regarding multiple statements in the same line, as you can tell by defrag.c, I'm actually a big fan of these (even without curly braces (not possible in this case).

So with regards to the above two concerns, I actually prefer the way @hwware wrote it.

However, I'm not necessarily the one who decides, and I think that 1) we should try to be consistent with the rest of the code in Redis, and 2) try to style each piece of code in a way that it's most readable (no strict rules), so a compromise between these two.

wow.. So much text about a damn white space... LOL.

Copy link
Member

Choose a reason for hiding this comment

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

since there's already one of these in the code base, we need to decide if we can merge that one, or (considering the other one is recent), reformat both.

i did a search in the project to see if this pattern was used elsewhere and found only two other cases (added by Salvatore a year ago):

if (tio_debug) { printf("E"); fflush(stdout); }

i suppose being a debug code that's rarely executed, he didn't want to pollute many lines with it.
similarly, in our case, trivial error handling code.
personally i think we can keep using this pattern.

@oranagra oranagra linked an issue Oct 16, 2020 that may be closed by this pull request
@oranagra oranagra added the state:to-be-merged The PR should be merged soon, even if not yet ready, this is used so that it won't be forgotten label Oct 18, 2020
@oranagra oranagra merged commit 04a0af9 into redis:unstable Oct 19, 2020
oranagra pushed a commit that referenced this pull request Oct 27, 2020
minor fix for a bug which happen on error handling code
and doesn't look like it could have caused any real harm
(fd number wouldn't have been reused yet)

(cherry picked from commit 04a0af9)
JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Nov 4, 2020
minor fix for a bug which happen on error handling code
and doesn't look like it could have caused any real harm
(fd number wouldn't have been reused yet)
jschmieg pushed a commit to memKeyDB/memKeyDB that referenced this pull request Nov 6, 2020
minor fix for a bug which happen on error handling code
and doesn't look like it could have caused any real harm
(fd number wouldn't have been reused yet)

(cherry picked from commit 04a0af9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state:to-be-merged The PR should be merged soon, even if not yet ready, this is used so that it won't be forgotten

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible double fclose

3 participants