All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: "René Scharfe" <l.s.r@web.de>
Cc: Git Mailing List <git@vger.kernel.org>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] daemon: use strbuf for hostname info
Date: Fri, 6 Mar 2015 16:06:27 -0500	[thread overview]
Message-ID: <20150306210627.GA24267@peff.net> (raw)
In-Reply-To: <54F96BF2.5000504@web.de>

On Fri, Mar 06, 2015 at 09:57:22AM +0100, René Scharfe wrote:

> Convert hostname, canon_hostname, ip_address and tcp_port to strbuf.
> This allows to get rid of the helpers strbuf_addstr_or_null() and STRARG
> because a strbuf always represents a valid (initially empty) string.
> sanitize_client() becomes unused and is removed as well.

Makes sense. I had a feeling that we might have cared about NULL versus
the empty string somewhere, but I did not see it in the patch below, so
I think it is fine.

> -static char *sanitize_client(const char *in)
> -{
> -	struct strbuf out = STRBUF_INIT;
> -	sanitize_client_strbuf(&out, in);
> -	return strbuf_detach(&out, NULL);
> -}

Not a big deal, but do we want to rename sanitize_client_strbuf to
sanitize_client? It only had the unwieldy name to distinguish it from
this one.

>  				if (port) {
> -					free(tcp_port);
> -					tcp_port = sanitize_client(port);
> +					strbuf_reset(&tcp_port);
> +					sanitize_client_strbuf(&tcp_port, port);

The equivalent of free() is strbuf_release(). I think it is reasonable
to strbuf_reset here, since we are about to write into it again anyway
(though I doubt it happens much in practice, since that would imply
multiple `host=` segments sent by the client). But later...

> -	free(hostname);
> -	free(canon_hostname);
> -	free(ip_address);
> -	free(tcp_port);
> -	hostname = canon_hostname = ip_address = tcp_port = NULL;
> +	strbuf_reset(&hostname);
> +	strbuf_reset(&canon_hostname);
> +	strbuf_reset(&ip_address);
> +	strbuf_reset(&tcp_port);

These probably want to all be strbuf_release(). Again, I doubt it
matters much because this is a forked daemon serving only a single
request (so they'll get freed by the OS soon anyway), but I think
freeing the memory here follows the original intent.

-Peff

  reply	other threads:[~2015-03-06 21:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-06  8:57 [PATCH] daemon: use strbuf for hostname info René Scharfe
2015-03-06 21:06 ` Jeff King [this message]
2015-03-07  0:20   ` René Scharfe
2015-03-07  1:08     ` Jeff King
2015-03-07 10:49       ` René Scharfe
2015-03-07  0:54   ` René Scharfe
2015-03-07  1:07     ` Jeff King
2015-03-07 10:50 ` [PATCH v2 1/2] " René Scharfe
2015-03-07 10:50 ` [PATCH v2 2/2] daemon: deglobalize hostname information René Scharfe

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=20150306210627.GA24267@peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=l.s.r@web.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.