From 8380c625c4fa027f666d95dc65b58cc38cd275c1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=2E=20David=20Ib=C3=A1=C3=B1ez?= <jdavid.ibp@gmail.com>
Date: Sat, 3 Mar 2012 17:33:57 +0100
Subject: [PATCH] Check for error after call to py_str_to_c_str

Fixes segfaults in 'Repository.create_commit' and 'Signature(...)'
Error reported by Han-Wen Nienhuys in the mailing list.
---
 pygit2.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/pygit2.c b/pygit2.c
index d8d65d8..cb4d826 100644
--- a/pygit2.c
+++ b/pygit2.c
@@ -694,6 +694,8 @@ Repository_create_commit(Repository *self, PyObject *args)
         goto out;
 
     message = py_str_to_c_str(py_message, encoding);
+    if (message == NULL)
+        goto out;
 
     err = git_tree_lookup_prefix(&tree, self->repo, &oid, (unsigned int)len);
     if (err < 0) {
@@ -2811,6 +2813,8 @@ Signature_init(Signature *self, PyObject *args, PyObject *kwds)
         return -1;
 
     name = py_str_to_c_str(py_name, encoding);
+    if (name == NULL)
+        return -1;
 
     err = git_signature_new(&signature, name, email, time, offset);
     if (err < 0) {