diff options
author | Guido van Rossum <guido@python.org> | 1995-01-30 12:45:38 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1995-01-30 12:45:38 (GMT) |
commit | d503913594f1f801f93d0d29df1ce86db9891315 (patch) | |
tree | 6b384d4da474cb7efd15f23f0d3053a0a52145fc /Modules | |
parent | 17448e24081eb713ac00d7bcb681f4f0d8abfcbf (diff) | |
download | cpython-d503913594f1f801f93d0d29df1ce86db9891315.zip cpython-d503913594f1f801f93d0d29df1ce86db9891315.tar.gz cpython-d503913594f1f801f93d0d29df1ce86db9891315.tar.bz2 |
plug leak and improve error handling in dbm_keys()
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/dbmmodule.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/Modules/dbmmodule.c b/Modules/dbmmodule.c index 867461f..2ec43ff 100644 --- a/Modules/dbmmodule.c +++ b/Modules/dbmmodule.c @@ -168,6 +168,7 @@ dbm_keys(dp, args) { register object *v, *item; datum key; + int err; if (dp == NULL || !is_dbmobject(dp)) { err_badcall(); @@ -179,11 +180,18 @@ dbm_keys(dp, args) if (v == NULL) return NULL; for (key = dbm_firstkey(dp->di_dbm); key.dptr; - key = dbm_nextkey(dp->di_dbm) ) { - item = newsizedstringobject(key.dptr, key.dsize); - if ( item == 0 ) - return NULL; - addlistitem(v, item); + key = dbm_nextkey(dp->di_dbm)) { + item = newsizedstringobject(key.dptr, key.dsize); + if (item == NULL) { + DECREF(v); + return NULL; + } + err = addlistitem(v, item); + DECREF(item); + if (err != 0) { + DECREF(v); + return NULL; + } } return v; } |