-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
stransport memory management improvements #3891
Conversation
de30549
to
368f7b4
Compare
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
368f7b4
to
b989514
Compare
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.