Skip to content

Commit b989514

Browse files
committed
stransport: do not use git_stream_free on uninitialized stransport
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.
1 parent 97e57e8 commit b989514

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/stransport_stream.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ int git_stransport_stream_new(git_stream **out, const char *host, const char *po
261261
st->ctx = SSLCreateContext(NULL, kSSLClientSide, kSSLStreamType);
262262
if (!st->ctx) {
263263
giterr_set(GITERR_NET, "failed to create SSL context");
264+
git__free(st);
264265
return -1;
265266
}
266267

@@ -270,7 +271,8 @@ int git_stransport_stream_new(git_stream **out, const char *host, const char *po
270271
(ret = SSLSetProtocolVersionMin(st->ctx, kTLSProtocol1)) != noErr ||
271272
(ret = SSLSetProtocolVersionMax(st->ctx, kTLSProtocol12)) != noErr ||
272273
(ret = SSLSetPeerDomainName(st->ctx, host, strlen(host))) != noErr) {
273-
git_stream_free((git_stream *)st);
274+
CFRelease(st->ctx);
275+
git__free(st);
274276
return stransport_error(ret);
275277
}
276278

0 commit comments

Comments
 (0)