Skip to content

PS-10949 Fix leaks in revoke/secret/server-info paths#25

Open
lukin-oleksiy wants to merge 2 commits intoPercona-Lab:masterfrom
lukin-oleksiy:fix_revoke_memory_leak
Open

PS-10949 Fix leaks in revoke/secret/server-info paths#25
lukin-oleksiy wants to merge 2 commits intoPercona-Lab:masterfrom
lukin-oleksiy:fix_revoke_memory_leak

Conversation

@lukin-oleksiy
Copy link
Copy Markdown
Contributor

@lukin-oleksiy lukin-oleksiy commented Mar 24, 2026

PS-10949 Fix leaks in revoke/secret/server-info paths; encode GET responses

https://perconadev.atlassian.net/browse/PS-10949

The summary of fixes from the 1st commit :

PS-10949 Fix revoke/SecretData decode leaks and add ASAN test target

https://perconadev.atlassian.net/browse/PS-10949 
 
libkmip/src/kmip.c: adds missing free paths to prevent decode-time leaks: 
new kmip_free_secret_data(...) 
new kmip_free_revoke_request_payload(...) 
new kmip_free_revoke_response_payload(...) 
 
wires these into existing dispatch in kmip_free_get_response_payload, 
kmip_free_request_batch_item, and kmip_free_response_batch_item for 
KMIP_OBJTYPE_SECRET_DATA and KMIP_OP_REVOKE. 
 
libkmip/include/kmip.h: exports kmip_free_secret_data(...) declaration. 
libkmip/src/tests.c: adds regression tests for decode paths that were leaking: 
test_decode_get_response_payload_secret_data 
test_decode_response_batch_item_revoke_payload 
both added to run_tests(). 
 
libkmip/src/CMakeLists.txt: introduces ASAN/LSAN test executable kmip_tests_asan and 
custom target run_tests_asan with leak detection enabled. 
 
README.md: updates usage docs with CMake build/run instructions and adds a 
“Run Tests (ASAN)” section showing run_tests_asan.

The second commit fixes other leaks detected by tests.c run with ASAN:

PS-10949 Fix remaining leask detected by ASAN test target

https://perconadev.atlassian.net/browse/PS-10949 
 
libkmip/src/kmip.c 
 
kmip_free_server_information was expanded from shallow field cleanup 
to full owned-memory cleanup. 
 
Adds a null guard (ctx/value) and explicitly frees each allocated 
TextString * field pointer after kmip_free_text_string. 
 
Adds cleanup for alternative_failover_endpoints, including draining/freing 
endpoint_list items and container allocations. 
 
Adds KMIP_OP_GET handling in kmip_encode_response_batch_item to encode 
GetResponsePayload (previously missing in that switch). 
 
libkmip/src/tests.c 
In test_encode_query_request_payload, adds kmip_destroy(&ctx) before return, 
fixing leaked test context memory. 
 
Net effect: this commit closes additional ASAN-reported leaks in server-info/test code paths and fixes missing 
GET response-payload encoding dispatch.

@satya-bodapati
Copy link
Copy Markdown

@lukin-oleksiy Thank you for fixing this quickly. Can you please revert the code change but keep tests to show that your new tests fail with ASAN (without code fix)? Please paste the trace reported by the tool?

https://perconadev.atlassian.net/browse/PS-10949

libkmip/src/kmip.c: adds missing free paths to prevent decode-time leaks:
new kmip_free_secret_data(...)
new kmip_free_revoke_request_payload(...)
new kmip_free_revoke_response_payload(...)

wires these into existing dispatch in kmip_free_get_response_payload,
kmip_free_request_batch_item, and kmip_free_response_batch_item for
KMIP_OBJTYPE_SECRET_DATA and KMIP_OP_REVOKE.

libkmip/include/kmip.h: exports kmip_free_secret_data(...) declaration.
libkmip/src/tests.c: adds regression tests for decode paths that were leaking:
test_decode_get_response_payload_secret_data
test_decode_response_batch_item_revoke_payload
both added to run_tests().

libkmip/src/CMakeLists.txt: introduces ASAN/LSAN test executable kmip_tests_asan and
custom target run_tests_asan with leak detection enabled.

README.md: updates usage docs with CMake build/run instructions and adds a
“Run Tests (ASAN)” section showing run_tests_asan.
https://perconadev.atlassian.net/browse/PS-10949

libkmip/src/kmip.c

kmip_free_server_information was expanded from shallow field cleanup
to full owned-memory cleanup.

Adds a null guard (ctx/value) and explicitly frees each allocated
TextString * field pointer after kmip_free_text_string.

Adds cleanup for alternative_failover_endpoints, including draining/freing
endpoint_list items and container allocations.

Adds KMIP_OP_GET handling in kmip_encode_response_batch_item to encode
GetResponsePayload (previously missing in that switch).

libkmip/src/tests.c
In test_encode_query_request_payload, adds kmip_destroy(&ctx) before return,
fixing leaked test context memory.

Net effect: this commit closes additional ASAN-reported leaks in server-info/test code paths and fixes missing
GET response-payload encoding dispatch.
@lukin-oleksiy lukin-oleksiy force-pushed the fix_revoke_memory_leak branch from 6edd05a to 2301151 Compare March 26, 2026 10:02
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