Thread (44 messages) 44 messages, 6 authors, 2017-01-19

Re: [PATCH v4 1/4] Avoid Coverity warning about unfree()d git_exec_path()

From: Stefan Beller <hidden>
Date: 2017-01-04 18:16:03

On Tue, Jan 3, 2017 at 1:33 PM, Johannes Schindelin
[off-list ref] wrote:
This patch was originally only to appease Coverity, but it actually *does*
plug a very real memory leak: previously, *every* call to git_exec_path()
*possibly* returned a newly-malloc()ed buffer. Now, the first call will
store that pointer in a static variable and reuse it later.

Could you maybe help me with improving the commit message?
As someone not familiar with that area of code, this explained it
enough for me to understand, so maybe:

    exec_cmd: do not leak via git_exec_path

    Every call to git_exec_path() possibly returned a newly-malloc()ed
    buffer. Now, the first call will allocate the buffer and subsequent
    calls return a pointer to it, which then prevents leaking memory
    on each call.

The return value of a "const char *" hints to the caller, that the memory
is not owned by the caller, do we need to be explicit there (i.e. a comment
declaring the memory ownership? Probably not.)

Thanks,
Stefan
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help