diff options
author | Magnus Ahltorp <map@kth.se> | 2016-07-11 16:52:19 +0200 |
---|---|---|
committer | Magnus Ahltorp <map@kth.se> | 2016-08-19 16:13:50 +0200 |
commit | c97d320d17d9c72a4daa620a43745b7aca3a9bde (patch) | |
tree | aab939e572b836f010d4393a588f231024f089d5 /c_src/permdbpy.c | |
parent | fadbdedabbc5b8c82f388ffa799a0e2c4958cf10 (diff) |
Better error handling when allocating and freeing permdb objectpermdb-alloc-fix-4
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; } |