summaryrefslogtreecommitdiff
path: root/Modules/sunaudiodev.c
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>1997-01-09 22:29:57 +0000
committerBarry Warsaw <barry@python.org>1997-01-09 22:29:57 +0000
commitcd36ee28b5d9dda6135b19cee8bd19b8c404f379 (patch)
treeea55101ee3a2fd8668e277d48a9a1a98a1aa481a /Modules/sunaudiodev.c
parent3612af784d7e3ad3d1273369a1e6ffbc5f08ebfd (diff)
downloadcpython-cd36ee28b5d9dda6135b19cee8bd19b8c404f379.tar.gz
Plugged a couple of potential return value problems, memory leaks, and
descriptor leaks.
Diffstat (limited to 'Modules/sunaudiodev.c')
-rw-r--r--Modules/sunaudiodev.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/Modules/sunaudiodev.c b/Modules/sunaudiodev.c
index bae17d5e30..a587ac6aa1 100644
--- a/Modules/sunaudiodev.c
+++ b/Modules/sunaudiodev.c
@@ -118,8 +118,10 @@ newsadobject(arg)
/* Create and initialize the object */
xp = PyObject_NEW(sadobject, &Sadtype);
- if (xp == NULL)
+ if (xp == NULL) {
+ close(fd);
return NULL;
+ }
xp->x_fd = fd;
xp->x_icount = xp->x_ocount = 0;
xp->x_isctl = (imode < 0);
@@ -162,9 +164,9 @@ sad_read(self, args)
}
#if 0
/* TBD: why print this message if you can handle the condition?
- assume it's debugging info which we can just as well get rid
- of. in any case this message should *not* be using printf!
- */
+ * assume it's debugging info which we can just as well get rid
+ * of. in any case this message should *not* be using printf!
+ */
if (count != size)
printf("sunaudio: funny read rv %d wtd %d\n", count, size);
#endif
@@ -211,7 +213,9 @@ sad_getinfo(self, args)
if (!PyArg_Parse(args, ""))
return NULL;
- rv = sads_alloc();
+ if (!(rv = sads_alloc()))
+ return NULL;
+
if (ioctl(self->x_fd, AUDIO_GETINFO, &rv->ai) < 0) {
PyErr_SetFromErrno(SunAudioError);
Py_DECREF(rv);
@@ -501,7 +505,8 @@ initsunaudiodev()
m = Py_InitModule("sunaudiodev", sunaudiodev_methods);
d = PyModule_GetDict(m);
SunAudioError = PyString_FromString("sunaudiodev.error");
- if ( SunAudioError == NULL ||
- PyDict_SetItemString(d, "error", SunAudioError) )
- Py_FatalError("can't define sunaudiodev.error");
+ if (SunAudioError)
+ PyDict_SetItemString(d, "error", SunAudioError);
+ if (PyErr_Occurred())
+ Py_FatalError("can't initialize sunaudiodev module");
}