Skip to content

[RDY] Coverity fix resource leaks 1b #804

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

Closed
wants to merge 4 commits into from

Conversation

aktau
Copy link
Contributor

@aktau aktau commented Jun 2, 2014

Because github is messing up and doesn't seem to even refer to travis anymore on PR #790, I've cherry-picked the relevant commits and posted them here.

/// @param name The name of the register
/// @param str The contents to write
/// @param len If >= 0, write `len` bytes of `str`. Otherwise, write
/// `strlen(str)` bytes. If `maxlen` is larger than the
Copy link
Contributor

Choose a reason for hiding this comment

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

Another maxlen -> len replacement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wow, this is getting ridiculous. I'll wait a few minutes to see if you pick out another stupid omission I made.

@aktau aktau mentioned this pull request Jun 7, 2014
aktau added 4 commits June 9, 2014 11:42
Also constified the arguments. The double casts for the `xstrdup` are ugly
but `vim_strsave` doesn't take `const` arguments for now so I couldn't keep
that.
Coverity detected a memory leak caused by not free'ing the value returned by
get_expr_line_src (basically vim_strsave(expr_line)). Replaced the copying
with direct manipulation of expr_line, since that also happens in other
parts of the codebase.

NOTE: I'm aware that this has different behaviour than vim_strnsave, namely
vim_strnsave always allocates `len` bytes, even if the string is shorter. I
don't see how that behaviour is helpful here though.
Also cleaned up the function a little bit.
It was a false positive, but it can't hurt to "fix" it.

Original warning:
CID 13685 (#1 of 1): Buffer not null terminated (BUFFER_SIZE)
6. buffer_size: Calling strncpy with a source string whose length (4 chars)
is greater than or equal to the size argument (4) will fail to
null-terminate b0p->b0_version.
@aktau
Copy link
Contributor Author

aktau commented Jun 9, 2014

@Hinidu decided to rebase, fixed the WARNING comment as well ;).

@Hinidu
Copy link
Contributor

Hinidu commented Jun 9, 2014

@aktau 👍 :-)

justinmk added a commit that referenced this pull request Jun 12, 2014
@justinmk
Copy link
Member

Merged!

@justinmk justinmk closed this Jun 12, 2014
dwb pushed a commit to dwb/neovim that referenced this pull request Feb 21, 2017
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