Skip to content

{bp-19839} tools/mkversion: Fix missing free in case of error. - #19843

Merged
xiaoxiang781216 merged 1 commit into
apache:releases/13.0from
jerpelea:bp-19839
Aug 15, 2026
Merged

{bp-19839} tools/mkversion: Fix missing free in case of error.#19843
xiaoxiang781216 merged 1 commit into
apache:releases/13.0from
jerpelea:bp-19839

Conversation

@jerpelea

Copy link
Copy Markdown
Contributor

Summary

  • According to strdup(3) manual strdup() allocates memory with malloc(3) and that memory should be released with free(3) when no longer needed.
  • For non existent path or file open error mkversion used exit() with no prior free() for allocated memory.
  • This change introduces ret variable, exit label, and free on exit in order to avoid potential memory leak.
  • tools/mkversion is a tiny short-lived utility and the memory gets freed by the OS upon application termination so that was not a bit issue, but now memory leak scanners should be happy as we have free() in pair to strdup().

Impact

RELEASE

Testing

CI

@jerpelea
jerpelea requested a review from Ouss4 as a code owner August 14, 2026 06:03
@github-actions github-actions Bot added Area: Tooling Size: S The size of the change in this PR is small labels Aug 14, 2026
@jerpelea

jerpelea commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

compiled locally without error
Create version.h
LN: platform/board to /apps/platform/dummy
Register: hello
Register: nsh
Register: sh
LD: nuttx
Memory region Used Size Region Size %age Used
flash: 145148 B 16 MB 0.87%
ilm: 0 GB 128 KB 0.00%
dlm: 11360 B 128 KB 8.67%
axi_sram: 0 GB 256 KB 0.00%
axi_sram_noncacheable: 0 GB 256 KB 0.00%
ahb_sram: 0 GB 32 KB 0.00%
CP: nuttx.hex

* According to strdup(3) manual strdup() allocates memory with malloc(3)
  and that memory should be released with free(3) when no longer needed.
* For non existent path or file open error mkversion used exit() with no
  prior free() for allocated memory.
* This change introduces ret variable, exit label, and free on exit in order
  to avoid potential memory leak.
* tools/mkversion is a tiny short-lived utility and the memory gets freed
  by the OS upon application termination so that was not a bit issue, but now
  memory leak scanners should be happy as we have free() in pair to strdup().

Reported-by: xjDeng.

Signed-off-by: Tomasz 'CeDeROM' CEDRO <tomek@cedro.info>
@xiaoxiang781216
xiaoxiang781216 merged commit 60a8dda into apache:releases/13.0 Aug 15, 2026
24 of 41 checks passed
@jerpelea
jerpelea deleted the bp-19839 branch August 15, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Tooling Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants