Skip to content

Address scan-build reported issues#112

Merged
ngie-eign merged 6 commits intofreebsd:masterfrom
ngie-eign:issue-77-scan-build
Jan 3, 2026
Merged

Address scan-build reported issues#112
ngie-eign merged 6 commits intofreebsd:masterfrom
ngie-eign:issue-77-scan-build

Conversation

@ngie-eign
Copy link
Contributor

@ngie-eign ngie-eign commented Dec 27, 2025

This change addresses several memory access issues cited by scan-build.

  • Clean up memory at an appropriate scope after use to avoid complexity with memory management.
  • Don't try accessing memory in do_test which could be out of bounds, as both 0 and 3 lines could be returned in the function prior to this change.

Relates to: #77

@ngie-eign ngie-eign requested review from bapt, emaste and ihoro December 27, 2025 23:59
@ngie-eign ngie-eign force-pushed the issue-77-scan-build branch 8 times, most recently from bf9d35e to 8a30aaf Compare December 29, 2025 06:36
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>
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>
@ngie-eign ngie-eign force-pushed the issue-77-scan-build branch from ca30c7e to bdbc70d Compare January 3, 2026 05:58
@ngie-eign ngie-eign merged commit 35ac9dd into freebsd:master Jan 3, 2026
2 checks passed
@ngie-eign ngie-eign deleted the issue-77-scan-build branch January 3, 2026 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant