cederom opened a new pull request, #19839:
URL: https://github.com/apache/nuttx/pull/19839
## 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
* Fix missing free() on error in tools/mkversion that could be detected as
memory leak.
## Testing
```
% uname -a
FreeBSD hexagon 14.4-RELEASE-p8 FreeBSD 14.4-RELEASE-p8
cederom-releng-14.4.8-igc_test_20260810-n273771-e99dffa6c4c8 GENERIC amd64
```
Before:
```
% git reflog -5
e64b28974bf (HEAD -> master, origin/master, origin/HEAD) HEAD@{0}: pull:
Fast-forward
21e9d0cafa0 HEAD@{1}: reset: moving to HEAD
21e9d0cafa0 HEAD@{2}: checkout: moving from
8f02eb156a83998f9152f8563089cbb2b1db3dc5 to master
8f02eb156a8 HEAD@{3}: checkout: moving from master to linguini1/nxdoom
21e9d0cafa0 HEAD@{4}: pull --all: Fast-forward
% git branch
* master
% cd tools
% gmake -f Makefile.host mkversion
% ./mkversion ..
/* version.h -- Autogenerated! Do not edit. */
#ifndef __INCLUDE_NUTTX_VERSION_H
#define __INCLUDE_NUTTX_VERSION_H
#define CONFIG_VERSION_STRING "10.4.0"
#define CONFIG_VERSION_MAJOR 10
#define CONFIG_VERSION_MINOR 4
#define CONFIG_VERSION_PATCH 0
#define CONFIG_VERSION_BUILD "e64b28974bf"
#define CONFIG_VERSION ((CONFIG_VERSION_MAJOR << 16) |\
(CONFIG_VERSION_MINOR << 8) |\
(CONFIG_VERSION_PATCH))
#endif /* __INCLUDE_NUTTX_VERSION_H */
```
After:
```
% git branch
* cederom-20260813-tools_mkversion_fix_missing_free_on_error
% cd tools
% gmake -f Makefile.host mkversion
% ./mkversion ..
/* version.h -- Autogenerated! Do not edit. */
#ifndef __INCLUDE_NUTTX_VERSION_H
#define __INCLUDE_NUTTX_VERSION_H
#define CONFIG_VERSION_STRING "13.0.0"
#define CONFIG_VERSION_MAJOR 13
#define CONFIG_VERSION_MINOR 0
#define CONFIG_VERSION_PATCH 0
#define CONFIG_VERSION_BUILD "e64b28974b-dirty"
#define CONFIG_VERSION ((CONFIG_VERSION_MAJOR << 16) |\
(CONFIG_VERSION_MINOR << 8) |\
(CONFIG_VERSION_PATCH))
#endif /* __INCLUDE_NUTTX_VERSION_H */
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]