Bug 2938 - minor memory leak during channel_init_channels()
Summary: minor memory leak during channel_init_channels()
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: ssh (show other bugs)
Version: 7.9p1
Hardware: ix86 All
: P5 trivial
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks: V_8_0
  Show dependency treegraph
 
Reported: 2018-12-05 03:09 AEDT by Markus
Modified: 2021-10-14 01:42 AEDT (History)
3 users (show)

See Also:


Attachments
patch to fix memory leak (691 bytes, patch)
2018-12-05 03:09 AEDT, Markus
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus 2018-12-05 03:09:46 AEDT
Created attachment 3208 [details]
patch to fix memory leak

Note: This is my first contribution to the openssh source and I'm porting my findings from a macOS/Windows port back to the original source. So please be gentle with my possible wrongdoings and errors.


In any case, I think this should be pretty straightforward:

In channels.c there is the channel_init_channels() function, which initially callocates memory for the sc structure and immediately also callocates and fills the sc->channel_pre and sc->channel_post pointer members.

Then, after a few lines of code, it finally calls the channel_handler_init(sc) function.

Now, the channel channel_handler_init() also callocates memory for pre and post and finally assigns its pointers into the sc struct pointer members.

        sc->channel_pre = pre;
        sc->channel_post = post;

However, at this point, sc->channel_pre and sc->channel_post are already filled with the pointers to the memory blocks which channel_init_channels() had allocated.

Thus these pointers get lost and the memory blocks leak.


Proposal: don't have chanell_init_channel() allocate these.  Let channel_init_channels() do it.


A patch is attached.
Comment 1 Damien Miller 2018-12-07 13:31:30 AEDT
Good catch - thanks! I've committed this and it will be in the openssh-8.0 release.
Comment 2 Damien Miller 2019-05-03 14:42:35 AEST
Move resolved bugs -> CLOSED after 8.0 release
Comment 3 Ahmed Sayeed 2021-10-14 01:42:29 AEDT
[spam removed]