Skip to content

tool_paramhlp: remove a malloc+free from proto2num()#20120

Closed
bagder wants to merge 1 commit into
masterfrom
bagder/proto2num-less-alloc
Closed

tool_paramhlp: remove a malloc+free from proto2num()#20120
bagder wants to merge 1 commit into
masterfrom
bagder/proto2num-less-alloc

Conversation

@bagder

@bagder bagder commented Dec 30, 2025

Copy link
Copy Markdown
Member

No description provided.

@bagder
bagder marked this pull request as ready for review December 30, 2025 23:14
@bagder
bagder requested a review from Copilot December 30, 2025 23:14

Copilot AI left a comment

Copy link
Copy Markdown

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 optimizes the proto2num() function by replacing a dynamically allocated protoset array with a stack-allocated one, eliminating a malloc/free pair. The change introduces a compile-time maximum protocol count (MAX_PROTOS) and uses a debug assertion to enforce this limit.

Key changes:

  • Introduced MAX_PROTOS constant (set to 30) to define the maximum number of protocols
  • Replaced dynamic allocation of protoset with stack allocation using the new constant
  • Removed the corresponding curlx_free() call and allocation failure check

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

Comment thread src/tool_paramhlp.c Outdated
Comment thread src/tool_paramhlp.c
@bagder
bagder force-pushed the bagder/proto2num-less-alloc branch from 0660d1b to caf8d44 Compare December 31, 2025 16:31
@bagder bagder closed this in 0c278cd Dec 31, 2025
@bagder
bagder deleted the bagder/proto2num-less-alloc branch December 31, 2025 16:59
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