Commit 2b882323 authored by Guido van Rossum's avatar Guido van Rossum

fix leaks in keys(); fix bug in close()

parent daff0e7c
...@@ -177,7 +177,6 @@ dbm_close(dp, args) ...@@ -177,7 +177,6 @@ dbm_close(dp, args)
if ( dp->di_dbm ) if ( dp->di_dbm )
gdbm_close(dp->di_dbm); gdbm_close(dp->di_dbm);
dp->di_dbm = NULL; dp->di_dbm = NULL;
DEL(dp);
INCREF(None); INCREF(None);
return None; return None;
} }
...@@ -189,6 +188,7 @@ dbm_keys(dp, args) ...@@ -189,6 +188,7 @@ dbm_keys(dp, args)
{ {
register object *v, *item; register object *v, *item;
datum key, okey={ (char *)NULL, 0}; datum key, okey={ (char *)NULL, 0};
int err;
if (dp == NULL || !is_dbmobject(dp)) { if (dp == NULL || !is_dbmobject(dp)) {
err_badcall(); err_badcall();
...@@ -202,10 +202,17 @@ dbm_keys(dp, args) ...@@ -202,10 +202,17 @@ dbm_keys(dp, args)
for (key = gdbm_firstkey(dp->di_dbm); key.dptr; for (key = gdbm_firstkey(dp->di_dbm); key.dptr;
key = gdbm_nextkey(dp->di_dbm,okey) ) { key = gdbm_nextkey(dp->di_dbm,okey) ) {
item = newsizedstringobject(key.dptr, key.dsize); item = newsizedstringobject(key.dptr, key.dsize);
if ( item == 0 ) if (item == 0) {
return NULL; DECREF(v);
addlistitem(v, item); return NULL;
}
err = addlistitem(v, item);
DECREF(item);
if(okey.dsize) free(okey.dptr); if(okey.dsize) free(okey.dptr);
if (err != 0) {
DECREF(v);
return NULL;
}
okey=key; okey=key;
} }
return v; return v;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment