Address scan-build reported issues#112
Merged
ngie-eign merged 6 commits intofreebsd:masterfrom Jan 3, 2026
Merged
Conversation
bf9d35e to
8a30aaf
Compare
Set the `m_tcname` parameter to NULL after calling free to ensure that a wild pointer isn't used after free. Signed-off-by: Enji Cooper <ngie@FreeBSD.org>
Prior to this change, exiting the function early would leak argv2. Free it unconditionally to avoid leaking the memory. Signed-off-by: Enji Cooper <ngie@FreeBSD.org>
8a30aaf to
ca30c7e
Compare
The code prior to this change would exit the function in select scenarios after allocating memory. Call `process_fini(..)` when exiting on error to ensure that all memory allocated as part of the function has been properly cleaned up. Signed-off-by: Enji Cooper <ngie@FreeBSD.org>
Split off memory initialization and management from other resource initialization so the memory can be allocated and freed once at a high-level instead of dealing with the complexity that the code had previously. NULL out memory after it's freed to avoid double-free situations. Initialize several variables, e.g., file descriptors, to bogus values to avoid issues with code being called twice in error and accidentally closing valid file descriptors. Signed-off-by: Enji Cooper <ngie@FreeBSD.org>
Refactor code to exit early in unpreventable scenarios and explicitly free in all scenarios when exiting the functions in the long paths. This avoids having to deal with some of the complexity around freeing temporary buffer space. Replace a malloc(3)+strcpy(3) use with strdup(3) while here to reduce complexity in `copy_contents(..)`. Signed-off-by: Enji Cooper <ngie@FreeBSD.org>
Shuffle around assertions with `nlines` to the appropriate locations and initialize `lines[]` to an array of `NULL` pointers to avoid reading unintialized memory. Signed-off-by: Enji Cooper <ngie@FreeBSD.org>
ca30c7e to
bdbc70d
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.
This change addresses several memory access issues cited by scan-build.
do_testwhich could be out of bounds, as both 0 and 3 lines could be returned in the function prior to this change.Relates to: #77