From 1138949a69f4967e9d333643ef08b21887232b1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 15 Aug 2012 20:13:32 +0200 Subject: [PATCH] diff: make sure malloc succeeds --- src/pygit2/diff.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/pygit2/diff.c b/src/pygit2/diff.c index c28db37..4d3b3e4 100644 --- a/src/pygit2/diff.c +++ b/src/pygit2/diff.c @@ -114,6 +114,11 @@ static int diff_hunk_cb( if (delta->old_file.path != NULL) { len = strlen(delta->old_file.path) + 1; old_path = malloc(sizeof(char) * len); + if (old_path == NULL) { + free(hunk->header); + return -1; + } + memcpy(old_path, delta->old_file.path, len); hunk->old_file = old_path; } else { @@ -123,6 +128,12 @@ static int diff_hunk_cb( if (delta->new_file.path != NULL) { len = strlen(delta->new_file.path) + 1; new_path = malloc(sizeof(char) * len); + if (new_path == NULL) { + free(hunk->header); + free(old_path); + return -1; + } + memcpy(new_path, delta->new_file.path, len); hunk->new_file = new_path; } else {