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:52:19 +0200 |
commit | 603c60e746435f2588df36c306c4dc960b79f6a9 (patch) | |
tree | 86c7639f0bf30a6e3b4ec743666cd6e1258fea6e /c_src/permdbpy.c | |
parent | 55e10be3a33d1858f07fd61e046c70d0b21fb5e9 (diff) |
Better error handling when allocating and freeing permdb objectpermdb-alloc-fix
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; } |