Thanks to visit codestin.com
Credit goes to github.com

Skip to content

stransport memory management improvements #3891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

pks-t
Copy link
Member

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

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
Copy link
Member Author

pks-t commented Aug 8, 2016

Embarassing typo... should probably wait until I've got a OS X VM at hand to test changes. Meh

@@ -230,7 +230,8 @@ static void stransport_free(git_stream *stream)
stransport_stream *st = (stransport_stream *) stream;

git_stream_free(st->io);
CFRelease(st->ctx);
if (st->ctx)
CFRelease(st->ctx);
Copy link
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
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
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
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