Fix memory and lifecycle clang-tidy warnings#13494
Open
Mic92 wants to merge 3 commits intoNixOS:masterfrom
Open
Fix memory and lifecycle clang-tidy warnings#13494Mic92 wants to merge 3 commits intoNixOS:masterfrom
Mic92 wants to merge 3 commits intoNixOS:masterfrom
Conversation
edolstra
reviewed
Jul 17, 2025
dbbf5f2 to
40391d4
Compare
40391d4 to
7b7f81a
Compare
Ericson2314
approved these changes
Jul 18, 2025
7b7f81a to
b7fbbf3
Compare
Clang-tidy warned about passing NULL to getcwd, which is a GNU extension and not portable. This could lead to undefined behavior on non-GNU systems. Introduced a getCurrentWorkingDirectory() helper function that: - Uses the standard C++ std::filesystem::current_path() - Wraps filesystem exceptions to throw SysError for consistency - Returns a std::filesystem::path for modern C++ usage Updated both absPath() and run.cc to use this new helper function, eliminating the platform-specific code and the clang-tidy warning. This fixes the warning: The 1st argument to 'getcwd' is NULL but should not be NULL [clang-analyzer-unix.StdCLibraryFunctions]
Replace malloc/free with std::unique_ptr to ensure memory is freed even if test assertions fail early. This prevents memory leaks when ASSERT_* macros cause early test exit. Fixes clang-tidy warning: Potential leak of memory pointed to by 'out_name' [clang-analyzer-unix.Malloc]
Getting rid of vfork() potentially can cause Nix to start failing when (for instance) a Nix process with a multi-gigabyte heap tries to run a small child program like git. Add NOLINT comments to suppress clang-tidy warnings about vfork being insecure. The performance benefit of vfork can be significant in memory-constrained situations.
b7fbbf3 to
95a4cb8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes several memory and lifecycle issues found by clang-tidy:
These fixes improve code safety and prevent potential crashes or memory leaks.