git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 1/2] t/helper/test-truncate: close file descriptor after truncation

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 22, 2025, 21:48 UTC
Message-ID
<xmqqqzy7rj6k.fsf@gitster.g>
In-Reply-To
<20250722174102.1876197-2-lhywkd22@gmail.com>
Hoyoung Lee <lhywkd22@gmail.com> writes:
Show 7 quoted lines
> Fix a resource leak where the file descriptor was not closed after
> truncating a file in t/helper/test-truncate.c.
>
> Signed-off-by: Hoyoung Lee <lhywkd22@gmail.com>
> ---
>  t/helper/test-truncate.c | 3 +++
>  1 file changed, 3 insertions(+)

While it is not wrong per-se, it is not like a function that can potentially be called number of times returns without closing it. Nobody other than the main() function would be calling this function, so the only thing that is done after this function returns to its caller is for the caller to return leading to exit from the process at which point the leftover file descriptor would be closed.

So I am a bit curious what triggered you to send in these changes. Are there some automated resource leak checker, without fixes like these whose output would be noisy with complaints about these "known leaking, no ill effects in practice, yet gets flagged by checkers" code to be useful, or something?

Will queue; thanks.
Show 13 quoted lines
> diff --git a/t/helper/test-truncate.c b/t/helper/test-truncate.c
> index 3931deaec7..104bc36cc0 100644
> --- a/t/helper/test-truncate.c
> +++ b/t/helper/test-truncate.c
> @@ -21,5 +21,8 @@ int cmd__truncate(int argc, const char **argv)
>  
>  	if (ftruncate(fd, (off_t) sz) < 0)
>  		die_errno("failed to truncate file");
> +	
> +	close(fd);
> +
>  	return 0;
>  }
Previous: Hoyoung LeeNext: Hoyoung Lee
Message 3 of 18 in “fix resource leaks in test helpers”
  1. 0/2 fix resource leaks in test helpersHoyoung Lee, Jul 22, 2025
  2. 1/2 t/helper/test-truncate: close file descriptor after truncationHoyoung Lee, Jul 22, 2025
  3. Junio C HamanoJul 22, 2025
  4. 2/2 t/helper/test-delta: fix possible resource leak and ensure safe cleanupHoyoung Lee, Jul 22, 2025
  5. Eric SunshineJul 23, 2025
  6. Jeff KingJul 23, 2025
  7. Jeff KingJul 23, 2025
  8. Eric SunshineJul 23, 2025
  9. Jeff KingJul 23, 2025
  10. 1/3 test-delta: handle errors with die()Jeff King, Jul 24, 2025
  11. 2/3 test-delta: use strbufs to hold input filesJeff King, Jul 24, 2025
  12. 3/3 test-delta: close output descriptor after useJeff King, Jul 24, 2025
  13. Eric SunshineJul 23, 2025
  14. Jeff KingJul 23, 2025
  15. Eric SunshineJul 23, 2025
  16. Junio C HamanoJul 23, 2025
  17. Junio C HamanoJul 23, 2025
  18. Junio C HamanoJul 23, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.