RDK-63722: Mem Usage validation with curl_easy_reset#282
RDK-63722: Mem Usage validation with curl_easy_reset#282yogeswaransky wants to merge 1 commit intodevelopfrom
Conversation
Signed-off-by: Yogeswaran K <yogeswaransky@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses a memory leak issue (RDK-63722) where internally duplicated strings (URLs, certs, etc.) were accumulating across handle reuses in a libcurl connection pool. The fix introduces curl_easy_reset() after each handle release and moves common option configuration to a new helper function called before each request.
Changes:
- Removes static curl option configuration from
init_connection_pool()and replaces it with a comment explaining the new approach. - Adds
curl_easy_reset()call inrelease_pool_handle()to free internally duplicated strings after each use. - Introduces a new
configure_common_curl_options()helper, called before eachcurl_easy_perform()in bothhttp_pool_get()andhttp_pool_post().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (idx >= 0 && idx < pool_size && pool_entries[idx].easy_handle) | ||
| { | ||
| curl_easy_reset(pool_entries[idx].easy_handle); | ||
| } | ||
|
|
||
| pthread_mutex_lock(&pool_mutex); | ||
| if (idx >= 0 && idx < pool_size) | ||
| { |
There was a problem hiding this comment.
The curl_easy_reset() call at line 421–424 occurs outside the pool_mutex lock, while the subsequent pool state update (marking the handle available) is protected by the mutex. If another thread acquires the same handle index between the reset and the mutex lock — for example, after a spurious or erroneous double-release — the reset could corrupt a handle that is actively in use. The curl_easy_reset() should be moved to inside the mutex-protected section, after the bounds and availability checks, to ensure the handle is not being used by another thread when it is reset.
| if (idx >= 0 && idx < pool_size && pool_entries[idx].easy_handle) | |
| { | |
| curl_easy_reset(pool_entries[idx].easy_handle); | |
| } | |
| pthread_mutex_lock(&pool_mutex); | |
| if (idx >= 0 && idx < pool_size) | |
| { | |
| pthread_mutex_lock(&pool_mutex); | |
| if (idx >= 0 && idx < pool_size) | |
| { | |
| if (pool_entries[idx].easy_handle) | |
| { | |
| curl_easy_reset(pool_entries[idx].easy_handle); | |
| } |
No description provided.