File: _portaudiomodule.c
Function: pa_read_stream
Error: ob_refcnt of new ref from call to Py_BuildValue is 1 too high
2198 static PyObject *
2199 pa_read_stream(PyObject *self, PyObject *args)
2200 {
2201   int err;
2202   int total_frames;
2203   short *sampleBlock;
2204   int num_bytes;
2205   PyObject *rv;
2206 
2207   PyObject *stream_arg;
2208   _pyAudio_Stream *streamObject;
2209 
2210   if (!PyArg_ParseTuple(args, "O!i",
when PyArg_ParseTuple() succeeds
taking False path
2211 			&_pyAudio_StreamType,
2212 			&stream_arg,
2213 			&total_frames))
2214     return NULL;
2215 
2216   /* make sure value is positive! */
2217   if (total_frames < 0) {
when considering range: 0 <= value <= 0x7fffffff
taking False path
2218     PyErr_SetString(PyExc_ValueError, "Invalid number of frames");
2219     return NULL;
2220   }
2221 
2222   streamObject = (_pyAudio_Stream *) stream_arg;
2223 
2224   if (!_is_open(streamObject)) {
when considering range: 1 <= value <= 0x7fffffff
taking False path
2225     PyErr_SetObject(PyExc_IOError,
2226 		    Py_BuildValue("(s,i)",
2227 				  "Stream closed",
2228 				  paBadStreamPtr));
2229     return NULL;
2230   }
2231 
2232   PaStream *stream = streamObject->stream;
2233   PaStreamParameters *inputParameters = streamObject->inputParameters;
2234   num_bytes = (total_frames) * (inputParameters->channelCount) *
when treating unknown struct PaStreamParameters * from _portaudiomodule.c:2233 as non-NULL
2235     (Pa_GetSampleSize(inputParameters->sampleFormat));
2236 
2237 #ifdef VERBOSE
2238   fprintf(stderr, "Allocating %d bytes\n", num_bytes);
2239 #endif
2240 
2241   rv = PyString_FromStringAndSize(NULL, num_bytes);
when PyString_FromStringAndSize() succeeds
2242   sampleBlock = (short *) PyString_AsString(rv);
PyString_AsString() returns ob_sval
2243 
2244   if (sampleBlock == NULL) {
taking False path
2245     PyErr_SetObject(PyExc_IOError,
2246 		    Py_BuildValue("(s,i)",
2247 				  "Out of memory",
2248 				  paInsufficientMemory));
2249     return NULL;
2250   }
2251 
2252   Py_BEGIN_ALLOW_THREADS
releasing the GIL by calling PyEval_SaveThread()
2253   err = Pa_ReadStream(stream, sampleBlock, total_frames);
2254   Py_END_ALLOW_THREADS
reacquiring the GIL by calling PyEval_RestoreThread()
2255 
2256   if (err != paNoError) {
when considering range: 1 <= value <= 0x7fffffff
taking True path
2257 
2258     /* ignore input overflow and output underflow */
2259     if (err & paInputOverflowed) {
taking True path
2260 
2261 #ifdef VERBOSE
2262       fprintf(stderr, "Input Overflow.\n");
2263 #endif
2264 
2265     } else if (err & paOutputUnderflowed) {
2266 
2267 #ifdef VERBOSE
2268       fprintf(stderr, "Output Underflow.\n");
2269 #endif
2270 
2271     } else {
2272       /* clean up */
2273       _cleanup_Stream_object(streamObject);
2274     }
2275 
2276     /* free the string buffer */
2277     Py_XDECREF(rv);
taking False path
when taking False path
calling tp_dealloc on PyStringObject allocated at _portaudiomodule.c:2241
2278 
2279     PyErr_SetObject(PyExc_IOError,
when Py_BuildValue() succeeds
calling PyErr_SetObject()
new ref from call to Py_BuildValue allocated at:     PyErr_SetObject(PyExc_IOError,
ob_refcnt is now refs: 1 + N where N >= 0
ob_refcnt is now refs: 1 + N where N >= 1
2280 		    Py_BuildValue("(s,i)",
2281 				  Pa_GetErrorText(err), err));
2282     return NULL;
2283   }
2284 
2285   return rv;
2286 }
ob_refcnt of new ref from call to Py_BuildValue is 1 too high
was expecting final ob_refcnt to be N + 0 (for some unknown N)
but final ob_refcnt is N + 1
found 8 similar trace(s) to this

File: _portaudiomodule.c
Function: pa_read_stream
Error: calling PyString_AsString with NULL as argument 1 (rv) at _portaudiomodule.c:2242
2198 static PyObject *
2199 pa_read_stream(PyObject *self, PyObject *args)
2200 {
2201   int err;
2202   int total_frames;
2203   short *sampleBlock;
2204   int num_bytes;
2205   PyObject *rv;
2206 
2207   PyObject *stream_arg;
2208   _pyAudio_Stream *streamObject;
2209 
2210   if (!PyArg_ParseTuple(args, "O!i",
when PyArg_ParseTuple() succeeds
taking False path
2211 			&_pyAudio_StreamType,
2212 			&stream_arg,
2213 			&total_frames))
2214     return NULL;
2215 
2216   /* make sure value is positive! */
2217   if (total_frames < 0) {
when considering range: 0 <= value <= 0x7fffffff
taking False path
2218     PyErr_SetString(PyExc_ValueError, "Invalid number of frames");
2219     return NULL;
2220   }
2221 
2222   streamObject = (_pyAudio_Stream *) stream_arg;
2223 
2224   if (!_is_open(streamObject)) {
when considering range: -0x80000000 <= value <= -1
taking False path
2225     PyErr_SetObject(PyExc_IOError,
2226 		    Py_BuildValue("(s,i)",
2227 				  "Stream closed",
2228 				  paBadStreamPtr));
2229     return NULL;
2230   }
2231 
2232   PaStream *stream = streamObject->stream;
2233   PaStreamParameters *inputParameters = streamObject->inputParameters;
2234   num_bytes = (total_frames) * (inputParameters->channelCount) *
when treating unknown struct PaStreamParameters * from _portaudiomodule.c:2233 as non-NULL
2235     (Pa_GetSampleSize(inputParameters->sampleFormat));
2236 
2237 #ifdef VERBOSE
2238   fprintf(stderr, "Allocating %d bytes\n", num_bytes);
2239 #endif
2240 
2241   rv = PyString_FromStringAndSize(NULL, num_bytes);
when PyString_FromStringAndSize() fails
2242   sampleBlock = (short *) PyString_AsString(rv);
calling PyString_AsString with NULL as argument 1 (rv) at _portaudiomodule.c:2242
PyString_AsString() invokes Py_TYPE() on the pointer via the PyString_Check() macro, thus accessing (NULL)->ob_type
2243 
2244   if (sampleBlock == NULL) {
2245     PyErr_SetObject(PyExc_IOError,
2246 		    Py_BuildValue("(s,i)",
2247 				  "Out of memory",
2248 				  paInsufficientMemory));
2249     return NULL;
2250   }
2251 
2252   Py_BEGIN_ALLOW_THREADS
2253   err = Pa_ReadStream(stream, sampleBlock, total_frames);
2254   Py_END_ALLOW_THREADS
2255 
2256   if (err != paNoError) {
2257 
2258     /* ignore input overflow and output underflow */
2259     if (err & paInputOverflowed) {
2260 
2261 #ifdef VERBOSE
2262       fprintf(stderr, "Input Overflow.\n");
2263 #endif
2264 
2265     } else if (err & paOutputUnderflowed) {
2266 
2267 #ifdef VERBOSE
2268       fprintf(stderr, "Output Underflow.\n");
2269 #endif
2270 
2271     } else {
2272       /* clean up */
2273       _cleanup_Stream_object(streamObject);
2274     }
2275 
2276     /* free the string buffer */
2277     Py_XDECREF(rv);
2278 
2279     PyErr_SetObject(PyExc_IOError,
2280 		    Py_BuildValue("(s,i)",
2281 				  Pa_GetErrorText(err), err));
2282     return NULL;
2283   }
2284 
2285   return rv;
2286 }