# [PATCH] sha1_file: remove an used fd variable

2 messages from 2017-04-16 to 2017-04-17. Participants: Sebastian Schuberth, Jeff King.
Thread: https://gitlist.dev/t/45714

## Sebastian Schuberth, 2017-04-16 19:04

Subject: [PATCH] sha1_file: remove an used fd variable
Message-ID: <0102015b7826824a-7bacaa78-5158-4d33-9615-e1a5bffea7a2-000000@eu-west-1.amazonses.com>
URL: https://gitlist.dev/e/0102015b7826824a-7bacaa78-5158-4d33-9615-e1a5bffea7a2-000000%40eu-west-1.amazonses.com

```
Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
---
 sha1_file.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 7106389..9ecf71f 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -3970,7 +3970,6 @@ int read_loose_object(const char *path,
 		      void **contents)
 {
 	int ret = -1;
-	int fd = -1;
 	void *map = NULL;
 	unsigned long mapsize;
 	git_zstream stream;
@@ -4020,7 +4019,5 @@ int read_loose_object(const char *path,
 out:
 	if (map)
 		munmap(map, mapsize);
-	if (fd >= 0)
-		close(fd);
 	return ret;
 }

--
https://github.com/git/git/pull/344

```

## Jeff King, 2017-04-17 01:41

Subject: Re: [PATCH] sha1_file: remove an used fd variable
Message-ID: <20170417014140.gxto2q76v6ajxwd3@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20170417014140.gxto2q76v6ajxwd3%40sigill.intra.peff.net
In-Reply-To: <0102015b7826824a-7bacaa78-5158-4d33-9615-e1a5bffea7a2-000000@eu-west-1.amazonses.com>

```
On Sun, Apr 16, 2017 at 07:04:01PM +0000, Sebastian Schuberth wrote:

> Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
> ---
>  sha1_file.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/sha1_file.c b/sha1_file.c
> index 7106389..9ecf71f 100644
> --- a/sha1_file.c
> +++ b/sha1_file.c
> @@ -3970,7 +3970,6 @@ int read_loose_object(const char *path,
>  		      void **contents)
>  {
>  	int ret = -1;
> -	int fd = -1;
>  	void *map = NULL;
>  	unsigned long mapsize;
>  	git_zstream stream;
> @@ -4020,7 +4019,5 @@ int read_loose_object(const char *path,
>  out:
>  	if (map)
>  		munmap(map, mapsize);
> -	if (fd >= 0)
> -		close(fd);
>  	return ret;

Thanks, this looks obviously correct. The mistake is mine; in an early
iteration of the series, the caller of map_sha1_file_1() was responsible
for opening the file itself, but I later switched it to take the path.

-Peff

```
