diff options
author | Magnus Ahltorp <map@kth.se> | 2016-07-11 16:52:19 +0200 |
---|---|---|
committer | Magnus Ahltorp <map@kth.se> | 2016-07-11 16:56:54 +0200 |
commit | c0054123f17da4d684e92fd746305986bf459628 (patch) | |
tree | ca6d05a653e3e1fe0320c0da372ba8f421bfd087 /c_src/permdbpy.c | |
parent | 34c827d599c840a5c09999a721d81115d0457d6a (diff) |
Better error handling when allocating and freeing permdb objectpermdb-alloc-fix-2
Diffstat (limited to 'c_src/permdbpy.c')
-rw-r--r-- | c_src/permdbpy.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/c_src/permdbpy.c b/c_src/permdbpy.c index beea36a..bfad068 100644 --- a/c_src/permdbpy.c +++ b/c_src/permdbpy.c @@ -45,8 +45,17 @@ PyTypeObject permdb_type = { permdb_object_py * permdb_alloc_py(const char *dbpath) { + struct permdb_object *permdb; + + permdb = permdb_alloc(dbpath); + + if (permdb == NULL) { + PyErr_SetString(PyExc_RuntimeError, "Cannot allocate permdb object"); + return NULL; + } + permdb_object_py *state = PyObject_New(permdb_object_py, &permdb_type); - state->permdb = permdb_alloc(dbpath); + state->permdb = permdb; return state; } |