-
Notifications
You must be signed in to change notification settings - Fork 6
Static analysis issues (mostly memleaks) now fixed #27
Conversation
Pull Request Test Coverage Report for Build 96
💛 - Coveralls |
arg.c
Outdated
@@ -761,6 +761,7 @@ enter_efsys(e, rdlnk) | |||
else { | |||
if (!(path = Readlink(ec))) | |||
return(1); | |||
(void)free((FREE_P *)ec); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The depth of indentation looks bad.
At a quick glance, ec is freed after returning from this function.
The indentation for free
should not align with "return (1)".
It should be one level left.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know why the indentation is messed up?
Because there are spaces before 'if' and tab before 'return'!
My god.
Then my editor's autoindent naturally copied the tab.
We need to be careful about this. Entire code of lsof is full of this mess.
misc.c
Outdated
@@ -1212,10 +1212,12 @@ Readlink(arg) | |||
stk[i] = (char *)NULL; | |||
} | |||
(void) free((FREE_P *)stk); | |||
stk = (char **)NULL; | |||
(void) free((FREE_P *)s1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation level of the second free should be the same as the first free.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here are spaces and tabs combined on one line (1214). I'll be damned.
Sorry. I'll take care of this, but I'm sure you can see this mistake was not intended and was hard to prevent.
misc.c
Outdated
@@ -1212,10 +1212,12 @@ Readlink(arg) | |||
stk[i] = (char *)NULL; | |||
} | |||
(void) free((FREE_P *)stk); | |||
stk = (char **)NULL; | |||
(void) free((FREE_P *)s1); | |||
stk = (char **)NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
misc.c
Outdated
ss = sx = 0; | ||
s1 = (char *)NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
misc.c
Outdated
op = (char *)NULL; | ||
return((char *)NULL); | ||
return((char *)NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this change of indentation level is not needed.
@@ -760,8 +760,8 @@ enter_efsys(e, rdlnk) | |||
path = ec; | |||
else { | |||
if (!(path = Readlink(ec))) | |||
return(1); | |||
(void)free((FREE_P *)ec); | |||
return(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line "return (1);" is nothing to do with the memleaks.
So, please, keep the line as the same as before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, return (1) has nothing to do with memleaks, but Readlink(ec) has.
On line 754 new string for ec is allocated. On line 762 Readlink returns new allocated string in some cases. Then ec is not used anymore and never freed.
For your sake the code of Readlink is so nasty that there are cases it returns ec back again.
So yeah, after finding (!!!) and peeking at Readlink() more thoroughly I concur ec cannot be freed, however there will be cases it WILL leak.
I will remove this part in next commit.
No description provided.