summaryrefslogtreecommitdiff
path: root/src/vector.c
diff options
context:
space:
mode:
authorVicent Marti <vicent@github.com>2014-04-06 16:22:29 +0200
committerVicent Marti <vicent@github.com>2014-04-06 16:22:29 +0200
commit52056db9c1d6cccf30fc2e22d9b391017bef5eea (patch)
treef0e6d66f0d2db9cd91231cf5f4d688c199449467 /src/vector.c
parent923c84008d6e3a4bf36ce08f9145a11b90f27185 (diff)
parent4998009a28929affb3f22274b1024bc5a8cdbfb6 (diff)
downloadlibgit2-52056db9c1d6cccf30fc2e22d9b391017bef5eea.tar.gz
Merge pull request #2250 from jacquesg/vector-leak
Don't lose our elements when calling git_vector_set()
Diffstat (limited to 'src/vector.c')
-rw-r--r--src/vector.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/vector.c b/src/vector.c
index c2c67e6b8..37ea07f0b 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -327,8 +327,10 @@ int git_vector_resize_to(git_vector *v, size_t new_length)
int git_vector_set(void **old, git_vector *v, size_t position, void *value)
{
- if (git_vector_resize_to(v, position + 1) < 0)
- return -1;
+ if (position + 1 > v->length) {
+ if (git_vector_resize_to(v, position + 1) < 0)
+ return -1;
+ }
if (old != NULL)
*old = v->contents[position];