Skip to content

RDK-63722: Mem Usage validation with curl_easy_reset#282

Open
yogeswaransky wants to merge 1 commit intodevelopfrom
mem/RDK-63722
Open

RDK-63722: Mem Usage validation with curl_easy_reset#282
yogeswaransky wants to merge 1 commit intodevelopfrom
mem/RDK-63722

Conversation

@yogeswaransky
Copy link
Copy Markdown
Contributor

No description provided.

Signed-off-by: Yogeswaran K <yogeswaransky@gmail.com>
Copilot AI review requested due to automatic review settings March 9, 2026 10:00
@yogeswaransky yogeswaransky requested a review from a team as a code owner March 9, 2026 10:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in release_pool_handle() to free internally duplicated strings after each use.
  • Introduces a new configure_common_curl_options() helper, called before each curl_easy_perform() in both http_pool_get() and http_pool_post().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +421 to 428
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)
{
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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);
}

Copilot uses AI. Check for mistakes.
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