From e93d0815a8de2806667851e31dbd06578db00f95 Mon Sep 17 00:00:00 2001 From: yuangli Date: Tue, 2 Aug 2022 14:35:27 +0100 Subject: attempt to fix nego.shallowarray memory leak --- src/libgit2/remote.c | 3 +++ src/libgit2/transports/smart.c | 6 ++++++ src/libgit2/transports/smart.h | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/libgit2/remote.c b/src/libgit2/remote.c index 02d271d7d..c3d3af530 100644 --- a/src/libgit2/remote.c +++ b/src/libgit2/remote.c @@ -22,6 +22,7 @@ #include "git2/types.h" #include "git2/oid.h" #include "git2/net.h" +#include "transports/smart.h" #define CONFIG_URL_FMT "remote.%s.url" #define CONFIG_PUSHURL_FMT "remote.%s.pushurl" @@ -2163,6 +2164,8 @@ 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/transports/smart.c b/src/libgit2/transports/smart.c index 9d1afeb05..df8e4da4a 100644 --- a/src/libgit2/transports/smart.c +++ b/src/libgit2/transports/smart.c @@ -510,3 +510,9 @@ 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 bc072d2fe..f9577cdee 100644 --- a/src/libgit2/transports/smart.h +++ b/src/libgit2/transports/smart.h @@ -203,4 +203,6 @@ struct git_shallowarray { git_array_oid_t array; }; +void git_shallowarray_free(git_shallowarray *array); + #endif -- cgit v1.2.1