Re: [PATCH v3/GSoC 2/5] path.c: implement xdg_runtime_dir()

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH v3/GSoC 2/5] path.c: implement xdg_runtime_dir()

From: Junio C Hamano <hidden>
Date: 2016-06-15 23:09:04

惠轶群 [off-list ref] writes:
After read the source code of strbuf more carefully, I get the conclusion
that if a strbuf is initialized with STRBUF_INIT but is not used, there is
no need to release it. Is it true?
If it is initialized with STRBUF_INIT and never used, there is no
reason for the variable to exist ;-)

Leaving the variable in the code, and not calling release on it at
the end, would be OK (i.e. there is no leak) today, but may invite
future bugs (e.g. people may use the variable to tentatively build
their string before the function returns to leave the scope of the
variable without adding _release() themselves).

Re: [PATCH v3/GSoC 2/5] path.c: implement xdg_runtime_dir()

From: 惠轶群 <hidden>
Date: 2016-06-15 23:09:04

2016-03-28 22:50 GMT+08:00 Junio C Hamano [off-list ref]:
惠轶群 [off-list ref] writes:
quoted
After read the source code of strbuf more carefully, I get the conclusion
that if a strbuf is initialized with STRBUF_INIT but is not used, there is
no need to release it. Is it true?
If it is initialized with STRBUF_INIT and never used, there is no
reason for the variable to exist ;-)
I mean, if some developer return before the strbuf is used, there seems
no need to release the strbuf according to the current implementation.

But I'm not sure whether this is suitable for the abstraction of strbuf.

For example:

    const char *enter_repo(const char *path, int strict)
    {
        static struct strbuf validated_path = STRBUF_INIT;
        static struct strbuf used_path = STRBUF_INIT;

        if (!path)
            return NULL; // no need to release, right?
        ...
    }

Leaving the variable in the code, and not calling release on it at
the end, would be OK (i.e. there is no leak) today, but may invite
future bugs (e.g. people may use the variable to tentatively build
their string before the function returns to leave the scope of the
variable without adding _release() themselves).
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help