Skip to content

ldap: fix minor leak on write callback error#21530

Closed
bagder wants to merge 1 commit into
masterfrom
bagder/ldap-error-leak
Closed

ldap: fix minor leak on write callback error#21530
bagder wants to merge 1 commit into
masterfrom
bagder/ldap-error-leak

Conversation

@bagder
Copy link
Copy Markdown
Member

@bagder bagder commented May 7, 2026

The 'ber' pointer could remain allocated in the exit path if the write callback returned error for one of the Curl_client_write() calls.

Reported-by: Andrew Nesbit

The 'ber' pointer could remain allocated in the exit path if the write
callback returned error for one of the Curl_client_write() calls.

Reported-by: Andrew Nesbit
@bagder bagder marked this pull request as ready for review May 7, 2026 16:04
@bagder bagder requested a review from Copilot May 7, 2026 16:13
Copy link
Copy Markdown

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 fixes a small memory leak in the LDAP transfer path by ensuring the BerElement *ber iterator state is always freed when exiting ldap_do() early due to a Curl_client_write() error (or other early-exit conditions).

Changes:

  • Hoist BerElement *ber to function scope so it remains visible on all exit paths.
  • Centralize ber cleanup by removing repeated per-error-path frees and adding a quit: cleanup free.
  • Avoid double-free by setting ber = NULL after the normal per-entry ber_free().

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

@bagder bagder closed this in 9249aad May 7, 2026
@bagder bagder deleted the bagder/ldap-error-leak branch May 7, 2026 20:58
outcast36 pushed a commit to greearb/curl that referenced this pull request Jun 3, 2026
The 'ber' pointer could remain allocated in the exit path if the write
callback returned error for one of the Curl_client_write() calls.

Reported-by: Andrew Nesbit
Closes curl#21530
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants