[ 
https://issues.apache.org/jira/browse/ZOOKEEPER-4975?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18042712#comment-18042712
 ] 

David commented on ZOOKEEPER-4975:
----------------------------------

Hi, I spent some time digging into this issue and wanted to summarize a couple 
of spots that appear closely related.

*Possible problematic locations:*

1. In {{zookeeper-client/zookeeper-client-c/src/zk_sasl.c}}, the function 
{{zoo_sasl_make_password_callbacks()}} allocates {{xcallbacks}} array but never 
frees it, leading to a memory leak. ([line 
597|https://github.com/apache/zookeeper/blob/7246445ec281f3dbf53dc54e970c914f39713903/zookeeper-client/zookeeper-client-c/src/zk_sasl.c#L597C26-L597C37])

2. In the same file, the function {{zoo_sasl_client_destroy()}} only nullifies 
{{sc->params.callbacks}} without freeing it, so previously allocated callbacks 
leak. ([Line 
123|https://github.com/apache/zookeeper/blob/7246445ec281f3dbf53dc54e970c914f39713903/zookeeper-client/zookeeper-client-c/src/zk_sasl.c#L123])

*Potential Fix:*

1. Release {{xcallbacks}} via {{free()}} in the client teardown path or provide 
an explicit function to free the SASL callbacks returned by 
{{zoo_sasl_make_basic_callbacks}}.

2. Insert 
{code:java}
free(sc->params.callbacks);
{code}
before setting 
{code:java}
sc->params.callbacks = NULL;
{code}

Let me know if this matches your understanding or if there’s anything else 
worth checking.

> memory leak when the c client opens SASL
> ----------------------------------------
>
>                 Key: ZOOKEEPER-4975
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-4975
>             Project: ZooKeeper
>          Issue Type: Bug
>          Components: c client
>    Affects Versions: 3.9.4
>            Reporter: qi.ji
>            Priority: Major
>
> zoo_sasl_make_basic_callbacks() malloc some memory, but never free it. Even 
> if I want to free it from the outside, I can't get the struct 
> zsasks_screen_ctx defined in the zk_sasl.c. At present, I can only create my 
> own callbacks function to avoid this problem. zoo_sasl_make_basic_callbacks 
> should be deleted or repaired.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to