# [PATCH] delete_ref(): fix uninitialized value, found by valgrind

3 messages from 2009-02-03 to 2009-02-04. Participants: Johannes Schindelin, Junio C Hamano.
Thread: https://gitlist.dev/t/17536

## Johannes Schindelin, 2009-02-03 18:12

Subject: [PATCH] delete_ref(): fix uninitialized value, found by valgrind
Message-ID: <alpine.DEB.1.00.0902031912290.9822@pacific.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0902031912290.9822%40pacific.mpi-cbg.de
In-Reply-To: <cover.1233684745u.git.johannes.schindelin@gmx.de>

```
The variable 'err' was not necessarily initialized before it was used.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 refs.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/refs.c b/refs.c
index b13e01b..ded7ec4 100644
--- a/refs.c
+++ b/refs.c
@@ -929,7 +929,7 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
 int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
 {
 	struct ref_lock *lock;
-	int err, i = 0, ret = 0, flag = 0;
+	int err = 0, i = 0, ret = 0, flag = 0;
 	struct stat loginfo;
 	int log = !lstat(git_path("logs/%s", refname), &loginfo);
 
-- 
1.6.1.2.574.g140d5

```

## Junio C Hamano, 2009-02-04 06:00

Subject: Re: [PATCH] delete_ref(): fix uninitialized value, found by valgrind
Message-ID: <7v7i467ndd.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v7i467ndd.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <alpine.DEB.1.00.0902031912290.9822@pacific.mpi-cbg.de>

```
Johannes Schindelin <johannes.schindelin@gmx.de> writes:

> The variable 'err' was not necessarily initialized before it was used.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>  refs.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/refs.c b/refs.c
> index b13e01b..ded7ec4 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -929,7 +929,7 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
>  int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
>  {
>  	struct ref_lock *lock;
> -	int err, i = 0, ret = 0, flag = 0;
> +	int err = 0, i = 0, ret = 0, flag = 0;
>  	struct stat loginfo;
>  	int log = !lstat(git_path("logs/%s", refname), &loginfo);

Sorry, I do not see it.

There are two uses of "err" in this function, both of which looks like:

	if (err && errno != ENOENT)

but both of these places have

	err = unlink(...)

immediately before it.

```

## Johannes Schindelin, 2009-02-04 09:57

Subject: Re: [PATCH] delete_ref(): fix uninitialized value, found by valgrind
Message-ID: <alpine.DEB.1.00.0902041056200.22763@intel-tinevez-2-302>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0902041056200.22763%40intel-tinevez-2-302
In-Reply-To: <7v7i467ndd.fsf@gitster.siamese.dyndns.org>

```
Hi,

On Tue, 3 Feb 2009, Junio C Hamano wrote:

> Johannes Schindelin <johannes.schindelin@gmx.de> writes:
> 
> > The variable 'err' was not necessarily initialized before it was used.
> >
> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> > ---
> >  refs.c |    2 +-
> >  1 files changed, 1 insertions(+), 1 deletions(-)
> >
> > diff --git a/refs.c b/refs.c
> > index b13e01b..ded7ec4 100644
> > --- a/refs.c
> > +++ b/refs.c
> > @@ -929,7 +929,7 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
> >  int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
> >  {
> >  	struct ref_lock *lock;
> > -	int err, i = 0, ret = 0, flag = 0;
> > +	int err = 0, i = 0, ret = 0, flag = 0;
> >  	struct stat loginfo;
> >  	int log = !lstat(git_path("logs/%s", refname), &loginfo);
> 
> Sorry, I do not see it.
> 
> There are two uses of "err" in this function, both of which looks like:
> 
> 	if (err && errno != ENOENT)
> 
> but both of these places have
> 
> 	err = unlink(...)
> 
> immediately before it.

I should know better by now than to base my work on the tip of my Git 
tree.  Sure enough I have an attempt at resolving the "deleting a branch 
deletes its reflog, too" issue, which has that bug.

Sorry for the noise,
Dscho

```
