stransport memory management improvements by pks-t · Pull Request #3891 · libgit2/libgit2 · GitHub
Skip to content

stransport memory management improvements#3891

Merged
carlosmn merged 1 commit into
libgit2:masterfrom
pks-t:pks/stransport-memory-management-improvements
Aug 9, 2016
Merged

stransport memory management improvements#3891
carlosmn merged 1 commit into
libgit2:masterfrom
pks-t:pks/stransport-memory-management-improvements

Conversation

@pks-t

@pks-t pks-t commented Aug 8, 2016

Copy link
Copy Markdown
Member

Some fixes to memory management I've encountered when reasoning about #3885. While these fixes probably won't fix the problems encountered in this ticket, I think they are a worthwhile improvement never the less.

@pks-t pks-t force-pushed the pks/stransport-memory-management-improvements branch from de30549 to 368f7b4 Compare August 8, 2016 13:02
@pks-t

pks-t commented Aug 8, 2016

Copy link
Copy Markdown
Member Author

Comment thread src/stransport_stream.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When would this be NULL? If we fail to create the context, we error out on the constructor itself.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed. The only reasoning behind this was as a safeguard. Anyway, might as well just drop it if you deem this to be unnecessary. The other fix is still valid, I guess.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's either this or the other block. With this patch we avoid calling the free function when it's NULL so it's either one or the other.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Okay, I've dropped this patch. Note though that previously we haven't been calling the free function either, as at the point of time when calling it we didn't yet initialize the free function pointer.

When failing to initialize a new stransport stream, we try to
release already allocated memory by calling out to
`git_stream_free`, which in turn called out to the stream's
`free` function pointer. As we only initialize the function
pointer later on, this leads to a `NULL` pointer exception.

Furthermore, plug another memory leak when failing to create the
SSL context.
@pks-t pks-t force-pushed the pks/stransport-memory-management-improvements branch from 368f7b4 to b989514 Compare August 9, 2016 06:39
@carlosmn carlosmn merged commit 26a8617 into libgit2:master Aug 9, 2016
@pks-t pks-t deleted the pks/stransport-memory-management-improvements branch October 10, 2016 07:03
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