Commits

Anonymous committed 2107388

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

Comments (0)

Files changed (1)

Modules/gdbmmodule.c

         if ( dp->di_dbm )
 		gdbm_close(dp->di_dbm);
 	dp->di_dbm = NULL;
-	DEL(dp);
 	INCREF(None);
 	return None;
 }
 {
 	register object *v, *item;
 	datum key, okey={ (char *)NULL, 0};
+	int err;
 
 	if (dp == NULL || !is_dbmobject(dp)) {
 		err_badcall();
 	for (key = gdbm_firstkey(dp->di_dbm); key.dptr;
 				key = gdbm_nextkey(dp->di_dbm,okey) ) {
 	    item = newsizedstringobject(key.dptr, key.dsize);
-	    if ( item == 0 )
-	      return NULL;
-	    addlistitem(v, item);
+	    if (item == 0) {
+		    DECREF(v);
+		    return NULL;
+	    }
+	    err = addlistitem(v, item);
+	    DECREF(item);
     	    if(okey.dsize) free(okey.dptr);
+	    if (err != 0) {
+		    DECREF(v);
+		    return NULL;
+	    }
     	    okey=key;
 	}
 	return v;