Skip to content

pr-2163/dscho/coverity-fixes-leaks-and-error-paths-v2

tagged this 05 Jul 08:24
I wanted to whittle down the many issues reported by Coverity in the Git for
Windows project. Turns out: The vast majority of the issues are false
positives. Most of the remaining issues are in core Git proper.

This effort was forced on pause while Coverity was down from May 16
[https://web.archive.org/web/20260516152422/https://scan.coverity.com/] to
June 22
[https://web.archive.org/web/20260622182153/https://scan.coverity.com/]).

Here is a first batch of fixes for those issues.

Changes since v1:

 * Edited the commit messages to put function names in backticks, and
   reflowed the messages afterwards.
 * Took Junio's suggestion to avoid (ab-)using errno to determine the return
   value of load_one_loose_object_map().
 * Dropped the obsolete patch "run_diff_files: avoid memory leak".
 * Rewrote the commit message of "dir: free allocations on parse-error paths
   in read_one_dir()" to clarify ownership of the allocated untracked/dirs
   buffers.
 * Changed "submodule: fix cwd leak in get_superproject_working_tree()" to
   reduce the cognitive load on the reader (i.e. to make it a lot easier to
   reason about the correctness of the patch).

Johannes Schindelin (12):
  load_one_loose_object_map(): fix resource leak
  loose: avoid closing invalid fd on error path
  download_https_uri_to_file(): do not leak fd upon failure
  run-command: avoid `close(-1)` in `start_command()` error paths
  line-log: avoid redundant copy that leaks in process_ranges
  dir: free allocations on parse-error paths in `read_one_dir()`
  submodule: fix cwd leak in `get_superproject_working_tree()`
  worktree: fix resource leaks when branch creation fails
  imap-send: avoid leaking the IMAP upload buffer
  reftable/table: release filter on error path
  fsmonitor: plug token-data leak on early daemon-startup failures
  mingw: make `exit_process()` own the process handle on all paths

 builtin/fsmonitor--daemon.c |  2 ++
 builtin/worktree.c          |  7 +++++--
 bundle-uri.c                |  2 +-
 compat/mingw.c              |  4 +---
 compat/win32/exit-process.h |  1 +
 dir.c                       |  9 +++++++--
 imap-send.c                 |  1 +
 line-log.c                  |  3 +--
 loose.c                     | 12 ++++++------
 reftable/table.c            |  4 ++++
 run-command.c               |  6 +++---
 submodule.c                 | 19 ++++++++++---------
 12 files changed, 42 insertions(+), 28 deletions(-)

base-commit: e9019fcafe0040228b8631c30f97ae1adb61bcdc

Submitted-As: https://lore.kernel.org/git/pull.2163.v2.git.1783239870.gitgitgadget@gmail.com
In-Reply-To: https://lore.kernel.org/git/pull.2163.git.1782889472.gitgitgadget@gmail.com
Assets 2
Loading