Merge pull request #658 from schu/remote-disconnect remote: don't free transport on disconnect
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
diff --git a/examples/network/fetch.c b/examples/network/fetch.c
index d4a3974..23046bd 100644
--- a/examples/network/fetch.c
+++ b/examples/network/fetch.c
@@ -93,6 +93,9 @@ int fetch(git_repository *repo, int argc, char **argv)
} while (!data.finished);
printf("\rReceived %d/%d objects in %d bytes\n", stats.processed, stats.total, bytes);
+ // Disconnect the underlying connection to prevent from idling.
+ git_remote_disconnect(remote);
+
// Update the references in the remote's namespace to point to the
// right commits. This may be needed even if there was no packfile
// to download, which can happen e.g. when the branches have been
diff --git a/src/remote.c b/src/remote.c
index 71cb627..98c2569 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -381,13 +381,8 @@ void git_remote_disconnect(git_remote *remote)
{
assert(remote);
- if (remote->transport != NULL) {
- if (remote->transport->connected)
+ if (remote->transport != NULL && remote->transport->connected)
remote->transport->close(remote->transport);
-
- remote->transport->free(remote->transport);
- remote->transport = NULL;
- }
}
void git_remote_free(git_remote *remote)
@@ -395,14 +390,21 @@ void git_remote_free(git_remote *remote)
if (remote == NULL)
return;
+ if (remote->transport != NULL) {
+ git_remote_disconnect(remote);
+
+ remote->transport->free(remote->transport);
+ remote->transport = NULL;
+ }
+
+ git_vector_free(&remote->refs);
+
git__free(remote->fetch.src);
git__free(remote->fetch.dst);
git__free(remote->push.src);
git__free(remote->push.dst);
git__free(remote->url);
git__free(remote->name);
- git_vector_free(&remote->refs);
- git_remote_disconnect(remote);
git__free(remote);
}