Commit 076141a137c411d970e4c9e0d725d91eac44e27c

Carlos Martín Nieto 2011-04-07T14:38:03

Add a few malloc checks Add checks to see if malloc failed when allocating the tag members and signature members. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>

diff --git a/src/signature.c b/src/signature.c
index 7c43979..bd64652 100644
--- a/src/signature.c
+++ b/src/signature.c
@@ -140,6 +140,9 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
 
 	name_length = name_end - buffer - 1;
 	sig->name = git__malloc(name_length + 1);
+	if (sig->name == NULL)
+		return GIT_ENOMEM;
+
 	memcpy(sig->name, buffer, name_length);
 	sig->name[name_length] = 0;
 	buffer = name_end + 1;
@@ -153,6 +156,9 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
 
 	email_length = email_end - buffer;
 	sig->email = git__malloc(email_length + 1);
+	if (sig->name == NULL)
+		return GIT_ENOMEM;
+
 	memcpy(sig->email, buffer, email_length);
 	sig->email[email_length] = 0;
 	buffer = email_end + 1;
diff --git a/src/tag.c b/src/tag.c
index c18f042..a340095 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -131,12 +131,17 @@ static int parse_tag_buffer(git_tag *tag, const char *buffer, const char *buffer
 	text_len = search - buffer;
 
 	tag->tag_name = git__malloc(text_len + 1);
+	if (tag->tag_name == NULL)
+		return GIT_ENOMEM;
+
 	memcpy(tag->tag_name, buffer, text_len);
 	tag->tag_name[text_len] = '\0';
 
 	buffer = search + 1;
 
 	tag->tagger = git__malloc(sizeof(git_signature));
+	if (tag->tagger == NULL)
+		return GIT_ENOMEM;
 
 	if ((error = git_signature__parse(tag->tagger, &buffer, buffer_end, "tagger ")) != 0) {
 		free(tag->tag_name);
@@ -147,6 +152,9 @@ static int parse_tag_buffer(git_tag *tag, const char *buffer, const char *buffer
 	text_len = buffer_end - ++buffer;
 
 	tag->message = git__malloc(text_len + 1);
+	if (tag->message == NULL)
+		return GIT_ENOMEM;
+
 	memcpy(tag->message, buffer, text_len);
 	tag->message[text_len] = '\0';