Skip to content

Fix incorrect memory freeing in build_pkcs11_uri() - #11

Open
andersm wants to merge 1 commit into
nxp-imx-support:masterfrom
andersm:build_uri_fixes
Open

Fix incorrect memory freeing in build_pkcs11_uri()#11
andersm wants to merge 1 commit into
nxp-imx-support:masterfrom
andersm:build_uri_fixes

Conversation

@andersm

@andersm andersm commented Mar 2, 2026

Copy link
Copy Markdown

Fix some memory handling errors introduced in 1c477bd.

Since the build_pkcs11_uri() function could not possibly return a valid URI, have those changes been tested at all?

The function build_pkcs11_uri() tries to free memory it should not.

The variable pkcs11_token_pin points to memory owned by the C library, and
freeing it can cause a segfault.
The variable pkcs11_uri holds the return value. Calling the FREE() macro on the
variable made the function always return a NULL pointer.
The variable env_result is unnecessarily freed twice.
@marioicastal

Copy link
Copy Markdown
Contributor

Thank you, @andersm, we are working on this issue and running tests

@lnksz lnksz mentioned this pull request Mar 4, 2026
@marioicastal

Copy link
Copy Markdown
Contributor

Hi @andersm,
The problem has been fixed PR #11. The fix address the incorrect memory handling in build_pkcs11_uri by ensuring proper memory ownership and cleanup before reassignment.
The update will be included in an upcoming release.
Thank you so much for reporting the issue

utkarshguptanxp pushed a commit that referenced this pull request Aug 14, 2026
- Use a const pointer to prevent modification of memory returned by getenv().
- Free env_result before reassigning it to prevent invalid memory operations and memory leaks.

Issue originally reported in PR #11.

Reported-by: @andersm
Signed-off-by: Mario Castaneda <mario.ignacio.castaneda.lopez@nxp.com>
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.

2 participants