Commit 9dcd8cee6efa6614660019516153a5b0e6249825

Vicent Marti 2014-01-13T06:09:34

Merge pull request #2039 from brodie/brodie/handle-null-on-free Fix places in public free() functions where NULL pointers aren't handled

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]);