Subject: Re: [PATCH 1/2] unix-socket: fix memory leak when chdir(3p) fails

From: Patrick Steinhardt <[email-masked]>
Date: Thu, 30 Jan 2025 07:02:51 +0100

On Wed, Jan 29, 2025 at 03:07:02PM -0500, Jeff King wrote:
> On Wed, Jan 29, 2025 at 09:21:39AM -0800, Junio C Hamano wrote:
> 
> > > This leads to a memory leak: when we have already populated the context
> > > with the original directory that we need to chdir(3p) back into, but
> > > then the chdir(3p) into the socket's parent directory fails, then we
> > > won't release the original directory's path. The leak is exposed by
> > > t0301, but only via Meson with `meson setup -Dsanitize=leak`:
> > 
> > Did you mean
> > 
> >     $ meson configure -Db_sanitize=leak
> >     $ meson test t0301-credential-cache

Oh, yes, I indeed forgot the `b_` prefix. Other than that I wanted to
abbreviate steps a bit so that I don't have to give the full sequence of
commands, but my attempt was somewhat lacking :)

> > I'll need to figure out how to make various tweaks at runtime
> > working with meson based build tree.  The next thing I need to
> > figure out is to see how to get verbose error output from the tests,
> > as I cannot just go back to the source tree and say "cd t && sh
> > t0301-credential-cache -v -i -x" because the build is out of tree.
> 
> I did:
> 
>   GIT_BUILD_DIR=$PWD/../build ./t0301-credential-cache.sh -v -i
> 
> but I don't know if there's an easier way from meson.

You can pass arbitrary arguments via `--test-args`:

    $ meson test -i --test-args=-vix t0301*

`-i` makes the test run interactively so that stdout/stderr remains
connected to your terminal, which also allows you to use `test_pause` et
al.

> (The "b_" prefix on "sanitize" confused me as well after reading the
> commit message).

You've probably been confused by the lack of "b_" in my commit message,
not by the prefix itself, which was a simple typo.

But regardless of that, in case anybody else reads this and wonders
what the prefix means: the "b_" prefix comes from "base options". These
are a couple of flags that Meson provides out of the box and control the
base mode that the compiler runs with. This includes e.g. sanitizers,
`-Wl,--as-needed`, LTO, precompiled headers and other stuff. These
options can be discovered by running `meson configure` in either a build
directory or the source directory.

Patrick