summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2011-10-01 12:58:55 +0200
committerVicent Marti <tanoku@gmail.com>2011-10-01 13:03:19 +0200
commit657ce4b5b6616967a17b7d4cc40c3ed02f01126e (patch)
tree27154ae97ec3636131c3979b51299fc8b6bea229 /src
parent1e5b263577a11723c8cf4b5912b1d55d22cdeb2e (diff)
downloadlibgit2-657ce4b5b6616967a17b7d4cc40c3ed02f01126e.tar.gz
http-transport: Properly cleanup the WSA context
Diffstat (limited to 'src')
-rw-r--r--src/transport-http.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/transport-http.c b/src/transport-http.c
index 32ab5abd7..736f21b85 100644
--- a/src/transport-http.c
+++ b/src/transport-http.c
@@ -348,10 +348,6 @@ static int http_close(git_transport *transport)
if (error < 0)
return git__throw(GIT_EOSERR, "Failed to close the socket: %s", strerror(errno));
-#ifdef GIT_WIN32
- WSACleanup();
-#endif
-
return GIT_SUCCESS;
}
@@ -363,6 +359,14 @@ static void http_free(git_transport *transport)
unsigned int i;
git_pkt *p;
+#ifdef GIT_WIN32
+ /* cleanup the WSA context. note that this context
+ * can be initialized more than once with WSAStartup(),
+ * and needs to be cleaned one time for each init call
+ */
+ WSACleanup();
+#endif
+
git_vector_foreach(refs, i, p) {
git_pkt_free(p);
}
@@ -374,13 +378,9 @@ static void http_free(git_transport *transport)
free(t);
}
-
int git_transport_http(git_transport **out)
{
transport_http *t;
-#ifdef GIT_WIN32
- int ret;
-#endif
t = git__malloc(sizeof(transport_http));
if (t == NULL)
@@ -393,15 +393,15 @@ int git_transport_http(git_transport **out)
t->parent.close = http_close;
t->parent.free = http_free;
- *out = (git_transport *) t;
-
#ifdef GIT_WIN32
- ret = WSAStartup(MAKEWORD(2,2), &t->wsd);
- if (ret != 0) {
- http_free(*out);
+ /* on win32, the WSA context needs to be initialized
+ * before any socket calls can be performed */
+ if (WSAStartup(MAKEWORD(2,2), &t->wsd) != 0) {
+ http_free(t);
return git__throw(GIT_EOSERR, "Winsock init failed");
}
#endif
+ *out = (git_transport *) t;
return GIT_SUCCESS;
}