summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-08-13 18:11:43 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2006-08-13 18:11:43 (GMT)
commit5aa96895d8d5d2c76d75842a5e3c79ef4f09d895 (patch)
tree93bbe446af17352bef64fdc377e6f0c7ef753345
parente9ac0bb16945d021d3340a6b96edda82be784228 (diff)
downloadcpython-5aa96895d8d5d2c76d75842a5e3c79ef4f09d895.zip
cpython-5aa96895d8d5d2c76d75842a5e3c79ef4f09d895.tar.gz
cpython-5aa96895d8d5d2c76d75842a5e3c79ef4f09d895.tar.bz2
Handle malloc and fopen failures more gracefully.
Klocwork 180-181
-rw-r--r--Modules/_bsddb.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c
index b39e6f2..6fef6c2 100644
--- a/Modules/_bsddb.c
+++ b/Modules/_bsddb.c
@@ -1797,7 +1797,6 @@ DB_join(DBObject* self, PyObject* args)
DBC** cursors;
DBC* dbc;
-
if (!PyArg_ParseTuple(args,"O|i:join", &cursorsObj, &flags))
return NULL;
@@ -1811,6 +1810,11 @@ DB_join(DBObject* self, PyObject* args)
length = PyObject_Length(cursorsObj);
cursors = malloc((length+1) * sizeof(DBC*));
+ if (!cursors) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+
cursors[length] = NULL;
for (x=0; x<length; x++) {
PyObject* item = PySequence_GetItem(cursorsObj, x);
@@ -2622,11 +2626,13 @@ DB_verify(DBObject* self, PyObject* args, PyObject* kwargs)
CHECK_DB_NOT_CLOSED(self);
if (outFileName)
outFile = fopen(outFileName, "w");
+ /* XXX(nnorwitz): it should probably be an exception if outFile
+ can't be opened. */
MYDB_BEGIN_ALLOW_THREADS;
err = self->db->verify(self->db, fileName, dbName, outFile, flags);
MYDB_END_ALLOW_THREADS;
- if (outFileName)
+ if (outFile)
fclose(outFile);
/* DB.verify acts as a DB handle destructor (like close); this was