summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryuangli <yuangli@mathworks.com>2022-08-02 16:30:48 +0100
committeryuangli <yuangli@mathworks.com>2022-08-02 16:30:48 +0100
commitda04d3fc5e737b990e884129241f2ea3cba4cf6a (patch)
treebf9cd6c4d9d62273b4a968a252004881f373d99d
parente93d0815a8de2806667851e31dbd06578db00f95 (diff)
downloadlibgit2-da04d3fc5e737b990e884129241f2ea3cba4cf6a.tar.gz
fix grafts and shallowarray memory leaks
-rw-r--r--src/libgit2/grafts.c3
-rw-r--r--src/libgit2/remote.c7
-rw-r--r--src/libgit2/repository.c6
-rw-r--r--src/libgit2/transports/smart.c6
-rw-r--r--src/libgit2/transports/smart.h2
5 files changed, 10 insertions, 14 deletions
diff --git a/src/libgit2/grafts.c b/src/libgit2/grafts.c
index f1054fa36..dd1be3434 100644
--- a/src/libgit2/grafts.c
+++ b/src/libgit2/grafts.c
@@ -43,6 +43,9 @@ int git_grafts_from_file(git_grafts **out, const char *path)
git_grafts *grafts = NULL;
int error;
+ if (*out)
+ return git_grafts_refresh(*out);
+
if ((error = git_grafts_new(&grafts)) < 0)
goto error;
diff --git a/src/libgit2/remote.c b/src/libgit2/remote.c
index c3d3af530..63346e941 100644
--- a/src/libgit2/remote.c
+++ b/src/libgit2/remote.c
@@ -2150,6 +2150,11 @@ void git_remote_free(git_remote *remote)
remote->transport = NULL;
}
+ if (remote->nego.shallow_roots) {
+ git_array_clear(remote->nego.shallow_roots->array);
+ git__free(remote->nego.shallow_roots);
+ }
+
git_vector_free(&remote->refs);
free_refspecs(&remote->refspecs);
@@ -2164,8 +2169,6 @@ void git_remote_free(git_remote *remote)
free_heads(&remote->local_heads);
git_vector_free(&remote->local_heads);
- git_shallowarray_free((remote->nego).shallow_roots);
-
git_push_free(remote->push);
git__free(remote->url);
git__free(remote->pushurl);
diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c
index 105ea647f..0d149a626 100644
--- a/src/libgit2/repository.c
+++ b/src/libgit2/repository.c
@@ -3346,13 +3346,11 @@ int git_repository__shallow_roots(git_array_oid_t *out, git_repository *repo) {
if (!repo->shallow_grafts && (error = load_grafts(repo)) < 0)
return error;
- if ((error = git_grafts_refresh(repo->shallow_grafts)) < 0) {
+ if ((error = git_grafts_refresh(repo->shallow_grafts)) < 0)
return error;
- }
- if ((error = git_grafts_get_oids(out, repo->shallow_grafts)) < 0) {
+ if ((error = git_grafts_get_oids(out, repo->shallow_grafts)) < 0)
return error;
- }
return 0;
}
diff --git a/src/libgit2/transports/smart.c b/src/libgit2/transports/smart.c
index df8e4da4a..9d1afeb05 100644
--- a/src/libgit2/transports/smart.c
+++ b/src/libgit2/transports/smart.c
@@ -510,9 +510,3 @@ int git_shallowarray_remove(git_shallowarray *array, git_oid *oid)
/* no git_array_removeā€¦ meh */
return -1;
}
-
-void git_shallowarray_free(git_shallowarray *array)
-{
- git_array_clear(array->array);
- git__free(array);
-}
diff --git a/src/libgit2/transports/smart.h b/src/libgit2/transports/smart.h
index f9577cdee..bc072d2fe 100644
--- a/src/libgit2/transports/smart.h
+++ b/src/libgit2/transports/smart.h
@@ -203,6 +203,4 @@ struct git_shallowarray {
git_array_oid_t array;
};
-void git_shallowarray_free(git_shallowarray *array);
-
#endif