From: Michael Blume <blume.mike@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Eric Sunshine <sunshine@sunshineco.com>,
Yi EungJun <semtlenori@gmail.com>, Git List <git@vger.kernel.org>,
Yi EungJun <eungjun.yi@navercorp.com>, Jeff King <peff@peff.net>,
Peter Krefting <peter@softwolves.pp.se>
Subject: Re: [PATCH v5 1/1] http: Add Accept-Language header if possible
Date: Wed, 3 Dec 2014 14:00:17 -0800 [thread overview]
Message-ID: <CAO2U3QgDzDTt-zujw1yk51HFdp4oACusXeZ59h-CUgU41vgDHw@mail.gmail.com> (raw)
In-Reply-To: <xmqqppc0wh33.fsf@gitster.dls.corp.google.com>
On Wed, Dec 3, 2014 at 1:37 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Eric Sunshine <sunshine@sunshineco.com> writes:
>
>>> @@ -515,6 +517,9 @@ void http_cleanup(void)
>>> cert_auth.password = NULL;
>>> }
>>> ssl_cert_password_required = 0;
>>> +
>>> + if (cached_accept_language)
>>> + strbuf_release(cached_accept_language);
>>
>> Junio already mentioned that this is leaking the memory of the strbuf
>> struct itself which was xmalloc()'d by get_accept_language().
>
> I actually didn't ;-) A singleton cached_accept_language strbuf
> itself being kept around, with its reuse by get_accept_language(),
> is fine and is not a leak. But clearing the strbuf alone will
> introduce correctness problem---the second HTTP connection will see
> an empty strbuf, get_accept_language() will say "we've already
> computed and the header we must issue is an empty string", which is
> not correct.
>
> In the fix-up "SQUASH???" commit I queued on top of this patch on
> 'pu', I had to run "sort -u" on the output to the standard error
> stream, as there seemed to be two HTTP connections and the actual
> output had two headers, even though the test expected only one in
> the output. I suspect that it is a fallout from this bug that the
> original code passed that test that expects only one.
>
>>> +static struct strbuf *get_accept_language(void)
>>
>> I find this API a bit strange. Use of strbuf to construct the returned
>> string is an implementation detail of this function. From the caller's
>> point of view, it should just be receiving a constant string: one
>> which it needs neither to modify nor free. Also, if the caller were to
>> modify the returned strbuf for some reason, then that modification
>> would impact all future calls to get_accept_language() since the
>> strbuf is 'static' and not recomputed. Instead, I would expect the
>> declaration to be:
>>
>> static const char *get_accept_language(void)
>
> Makes sense to me.
>
>>> + /* Put a q-factor only if it is less than 1.0. */
>>> + if (q < max_q)
>>> + strbuf_addf(cached_accept_language, q_format, q);
>>> +
>>> + if (q > 1)
>>> + q--;
>
> I didn't mention this but if q ever goes below 1, wouldn't it mean
> that there is no point continuing this loop?
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
This seems to be failing under Mac OS for me
not ok 25 - git client sends Accept-Language based on LANGUAGE,
LC_ALL, LC_MESSAGES and LANG
#
# check_language "ko-KR, *;q=0.1" ko_KR.UTF-8 de_DE.UTF-8 ja_JP.UTF-8
en_US.UTF-8 &&
# check_language "de-DE, *;q=0.1" "" de_DE.UTF-8 ja_JP.UTF-8
en_US.UTF-8 &&
# check_language "ja-JP, *;q=0.1" "" "" ja_JP.UTF-8
en_US.UTF-8 &&
# check_language "en-US, *;q=0.1" "" "" ""
en_US.UTF-8
#
next prev parent reply other threads:[~2014-12-03 22:00 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-19 17:58 [PATCH v4 0/1] http: Add Accept-Language header if possible Yi EungJun
2014-07-19 17:58 ` [PATCH v4 1/1] " Yi EungJun
2014-07-21 19:01 ` Junio C Hamano
2014-08-03 7:35 ` Yi, EungJun
2014-12-02 12:12 ` [PATCH v5 0/1] " Yi EungJun
2014-12-02 12:12 ` [PATCH v5 1/1] " Yi EungJun
2014-12-03 18:22 ` Junio C Hamano
2014-12-03 19:31 ` Eric Sunshine
2014-12-03 21:37 ` Junio C Hamano
2014-12-03 22:00 ` Michael Blume [this message]
2014-12-03 22:06 ` Michael Blume
2014-12-22 16:44 ` [PATCH v6 0/1] " Yi EungJun
2014-12-22 16:44 ` [PATCH v6 1/1] " Yi EungJun
2014-12-22 19:34 ` Junio C Hamano
2014-12-24 20:35 ` Eric Sunshine
2014-12-29 16:18 ` Junio C Hamano
2015-01-18 12:23 ` [PATCH v7 0/1] " Yi EungJun
2015-01-18 12:26 ` [PATCH v7 1/1] " Yi EungJun
2015-01-18 15:14 ` Torsten Bögershausen
2015-01-19 20:21 ` [PATCH v6 0/1] " Eric Sunshine
2015-01-22 7:54 ` [PATCH v7 1/1] " Junio C Hamano
2015-01-27 15:51 ` [PATCH v8 0/1] " Yi EungJun
2015-01-27 15:51 ` [PATCH] " Yi EungJun
2015-01-27 23:34 ` Junio C Hamano
2015-01-28 6:15 ` Junio C Hamano
2015-01-28 11:59 ` Yi, EungJun
2015-01-28 12:04 ` [PATCH v9 0/1] " Yi EungJun
2015-01-28 12:04 ` [PATCH v9 1/1] " Yi EungJun
2015-02-25 22:52 ` Junio C Hamano
2015-02-26 3:04 ` Jeff King
2015-02-26 3:10 ` Jeff King
2015-02-26 20:59 ` Junio C Hamano
2015-02-26 21:33 ` Jeff King
2015-02-26 21:42 ` Junio C Hamano
2015-02-26 21:47 ` Stefan Beller
2015-02-26 22:06 ` Jeff King
2015-02-26 22:07 ` Jeff King
2015-02-26 22:26 ` Stefan Beller
2015-02-26 22:36 ` Jeff King
2015-02-26 22:45 ` Jeff King
2015-02-26 23:29 ` Junio C Hamano
2015-02-26 22:13 ` Junio C Hamano
2015-01-29 6:19 ` [PATCH v9 0/1] " Junio C Hamano
2015-01-30 17:23 ` Yi, EungJun
2015-03-06 16:13 ` [PATCH] http: Include locale.h when using setlocale() Ævar Arnfjörð Bjarmason
2015-03-06 19:01 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAO2U3QgDzDTt-zujw1yk51HFdp4oACusXeZ59h-CUgU41vgDHw@mail.gmail.com \
--to=blume.mike@gmail.com \
--cc=eungjun.yi@navercorp.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
--cc=peter@softwolves.pp.se \
--cc=semtlenori@gmail.com \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).