Allocate channelName dynamically to shrink WOLFSSH struct by ~4KB#1104
Open
aidangarske wants to merge 1 commit into
Open
Allocate channelName dynamically to shrink WOLFSSH struct by ~4KB#1104aidangarske wants to merge 1 commit into
aidangarske wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces per-connection memory usage by changing WOLFSSH.channelName from a fixed-size inline buffer to a dynamically allocated buffer sized to the actual subsystem/exec name, and adds API tests to cover the updated channel-type/name behavior.
Changes:
- Replace
WOLFSSH.channelName[WOLFSSH_MAX_CHN_NAMESZ]withbyte* channelNameand allocate/free it dynamically. - Update
wolfSSH_SetChannelType()to avoid realloc churn when the channel name is unchanged and to NUL-terminate stored names. - Add
test_wolfSSH_SetChannelTypeto cover the new/updated branches and edge cases.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
wolfssh/internal.h |
Shrinks WOLFSSH by making channelName a pointer instead of a 4KB inline array. |
src/ssh.c |
Implements dynamic allocation + “unchanged name” fast-path in wolfSSH_SetChannelType(). |
src/internal.c |
Frees channelName in SshResourceFree() and adjusts debug logging in SendChannelRequest(). |
tests/api.c |
Adds a new API test to validate wolfSSH_SetChannelType() behavior across edge cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
84498ed to
c3e98a7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Converts the WOLFSSH.channelName field from a fixed 4096-byte inline array to a
dynamically-allocated buffer sized to the actual subsystem/exec name, cutting wolfSSH_new()'s per-connection allocation by 4096 bytes with no change to public
API behavior. It also short-circuits the allocation when the name is unchanged,
so the non-blocking SFTP/SCP handshake retry loops no longer churn malloc/free
on every poll.
Measured wolfSSH_new() allocation (−4096 B in every config):
Adds test_wolfSSH_SetChannelType covering the full branch set (NULL/zero/oversize
name, store+NUL-terminate, unchanged-name no-op, replace/free-previous, EXEC
fallthrough, unknown-type and server-side EXEC rejection).
Fixes concerns in: ZD 21984