Merge pull request #2039 from brodie/brodie/handle-null-on-free Fix places in public free() functions where NULL pointers aren't handled
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
diff --git a/src/branch.c b/src/branch.c
index ef71c2c..9ed0add 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -181,6 +181,9 @@ void git_branch_iterator_free(git_branch_iterator *_iter)
{
branch_iter *iter = (branch_iter *) _iter;
+ if (iter == NULL)
+ return;
+
git_reference_iterator_free(iter->iter);
git__free(iter);
}
diff --git a/src/config.c b/src/config.c
index 056a6ae..b8d78c2 100644
--- a/src/config.c
+++ b/src/config.c
@@ -927,6 +927,9 @@ int git_config_next(git_config_entry **entry, git_config_iterator *iter)
void git_config_iterator_free(git_config_iterator *iter)
{
+ if (iter == NULL)
+ return;
+
iter->free(iter);
}
diff --git a/src/odb.c b/src/odb.c
index b208b27..b413f83 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -949,6 +949,9 @@ int git_odb_stream_read(git_odb_stream *stream, char *buffer, size_t len)
void git_odb_stream_free(git_odb_stream *stream)
{
+ if (stream == NULL)
+ return;
+
git__free(stream->hash_ctx);
stream->free(stream);
}
diff --git a/src/oid.c b/src/oid.c
index d56b6af..567b6cf 100644
--- a/src/oid.c
+++ b/src/oid.c
@@ -314,6 +314,9 @@ git_oid_shorten *git_oid_shorten_new(size_t min_length)
void git_oid_shorten_free(git_oid_shorten *os)
{
+ if (os == NULL)
+ return;
+
git__free(os->nodes);
git__free(os);
}
diff --git a/src/refs.c b/src/refs.c
index c8a833b..ce172aa 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -724,6 +724,9 @@ int git_reference_next_name(const char **out, git_reference_iterator *iter)
void git_reference_iterator_free(git_reference_iterator *iter)
{
+ if (iter == NULL)
+ return;
+
git_refdb_iterator_free(iter);
}
diff --git a/src/util.c b/src/util.c
index 81a64c7..f977a9b 100644
--- a/src/util.c
+++ b/src/util.c
@@ -140,6 +140,10 @@ int git_libgit2_opts(int key, ...)
void git_strarray_free(git_strarray *array)
{
size_t i;
+
+ if (array == NULL)
+ return;
+
for (i = 0; i < array->count; ++i)
git__free(array->strings[i]);