File: src/_portaudiomodule.c
Function: pa_read_stream
Error: memory leak: ob_refcnt of new ref from call to Py_BuildValue is 1 too high
2409 static PyObject *
2410 pa_read_stream(PyObject *self, PyObject *args)
2411 {
2412   int err;
2413   int total_frames;
2414   short *sampleBlock;
2415   int num_bytes;
2416   PyObject *rv;
2417 
2418   PyObject *stream_arg;
2419   _pyAudio_Stream *streamObject;
2420   PaStream *stream;
2421   PaStreamParameters *inputParameters;
2422 
2423   if (!PyArg_ParseTuple(args, "O!i",
when PyArg_ParseTuple() succeeds
taking False path
2424 			&_pyAudio_StreamType,
2425 			&stream_arg,
2426 			&total_frames))
2427     return NULL;
2428 
2429   /* make sure value is positive! */
2430   if (total_frames < 0) {
when considering range: 0 <= value <= 0x7fffffff
taking False path
2431     PyErr_SetString(PyExc_ValueError, "Invalid number of frames");
2432     return NULL;
2433   }
2434 
2435   streamObject = (_pyAudio_Stream *) stream_arg;
2436 
2437   if (!_is_open(streamObject)) {
when considering range: -0x80000000 <= value <= -1
taking False path
2438     PyErr_SetObject(PyExc_IOError,
2439 		    Py_BuildValue("(s,i)",
2440 				  "Stream closed",
2441 				  paBadStreamPtr));
2442     return NULL;
2443   }
2444 
2445   stream = streamObject->stream;
2446   inputParameters = streamObject->inputParameters;
2447   num_bytes = (total_frames) * (inputParameters->channelCount) *
when treating unknown struct PaStreamParameters * from src/_portaudiomodule.c:2446 as non-NULL
2448     (Pa_GetSampleSize(inputParameters->sampleFormat));
2449 
2450 #ifdef VERBOSE
2451   fprintf(stderr, "Allocating %d bytes\n", num_bytes);
2452 #endif
2453 
2454   rv = PyBytes_FromStringAndSize(NULL, num_bytes);
when PyBytes_FromStringAndSize() succeeds
2455   sampleBlock = (short *) PyBytes_AsString(rv);
2456 
2457   if (sampleBlock == NULL) {
when treating unknown char * from src/_portaudiomodule.c:2455 as non-NULL
taking False path
2458     PyErr_SetObject(PyExc_IOError,
2459 		    Py_BuildValue("(s,i)",
2460 				  "Out of memory",
2461 				  paInsufficientMemory));
2462     return NULL;
2463   }
2464 
2465   Py_BEGIN_ALLOW_THREADS
releasing the GIL by calling PyEval_SaveThread()
2466   err = Pa_ReadStream(stream, sampleBlock, total_frames);
2467   Py_END_ALLOW_THREADS
reacquiring the GIL by calling PyEval_RestoreThread()
2468 
2469   if (err != paNoError) {
when considering range: -0x80000000 <= value <= -1
taking True path
2470 
2471     /* ignore input overflow and output underflow */
2472     if (err & paInputOverflowed) {
taking True path
2473 
2474 #ifdef VERBOSE
2475       fprintf(stderr, "Input Overflow.\n");
2476 #endif
2477 
2478     } else if (err & paOutputUnderflowed) {
2479 
2480 #ifdef VERBOSE
2481       fprintf(stderr, "Output Underflow.\n");
2482 #endif
2483 
2484     } else {
2485       /* clean up */
2486       _cleanup_Stream_object(streamObject);
2487     }
2488 
2489     /* free the string buffer */
2490     Py_XDECREF(rv);
taking True path
when taking True path
2491 
2492     PyErr_SetObject(PyExc_IOError,
when Py_BuildValue() succeeds
calling PyErr_SetObject()
new ref from call to Py_BuildValue was allocated at:     PyErr_SetObject(PyExc_IOError,
ob_refcnt is now refs: 1 owned
ob_refcnt is now refs: 1 owned, 1 borrowed
2493 		    Py_BuildValue("(s,i)",
2494 				  Pa_GetErrorText(err), err));
2495     return NULL;
2496   }
2497 
2498   return rv;
2499 }

File: src/_portaudiomodule.c
Function: pa_read_stream
Error: memory leak: ob_refcnt of '*rv' is 1 too high
2409 static PyObject *
2410 pa_read_stream(PyObject *self, PyObject *args)
2411 {
2412   int err;
2413   int total_frames;
2414   short *sampleBlock;
2415   int num_bytes;
2416   PyObject *rv;
2417 
2418   PyObject *stream_arg;
2419   _pyAudio_Stream *streamObject;
2420   PaStream *stream;
2421   PaStreamParameters *inputParameters;
2422 
2423   if (!PyArg_ParseTuple(args, "O!i",
when PyArg_ParseTuple() succeeds
taking False path
2424 			&_pyAudio_StreamType,
2425 			&stream_arg,
2426 			&total_frames))
2427     return NULL;
2428 
2429   /* make sure value is positive! */
2430   if (total_frames < 0) {
when considering range: 0 <= value <= 0x7fffffff
taking False path
2431     PyErr_SetString(PyExc_ValueError, "Invalid number of frames");
2432     return NULL;
2433   }
2434 
2435   streamObject = (_pyAudio_Stream *) stream_arg;
2436 
2437   if (!_is_open(streamObject)) {
when considering range: -0x80000000 <= value <= -1
taking False path
2438     PyErr_SetObject(PyExc_IOError,
2439 		    Py_BuildValue("(s,i)",
2440 				  "Stream closed",
2441 				  paBadStreamPtr));
2442     return NULL;
2443   }
2444 
2445   stream = streamObject->stream;
2446   inputParameters = streamObject->inputParameters;
2447   num_bytes = (total_frames) * (inputParameters->channelCount) *
when treating unknown struct PaStreamParameters * from src/_portaudiomodule.c:2446 as non-NULL
2448     (Pa_GetSampleSize(inputParameters->sampleFormat));
2449 
2450 #ifdef VERBOSE
2451   fprintf(stderr, "Allocating %d bytes\n", num_bytes);
2452 #endif
2453 
2454   rv = PyBytes_FromStringAndSize(NULL, num_bytes);
when PyBytes_FromStringAndSize() succeeds
'*rv' was allocated at:   rv = PyBytes_FromStringAndSize(NULL, num_bytes);
ob_refcnt is now refs: 1 owned
2455   sampleBlock = (short *) PyBytes_AsString(rv);
2456 
2457   if (sampleBlock == NULL) {
when treating unknown char * from src/_portaudiomodule.c:2455 as NULL
taking True path
2458     PyErr_SetObject(PyExc_IOError,
when Py_BuildValue() succeeds
calling PyErr_SetObject()
2459 		    Py_BuildValue("(s,i)",
2460 				  "Out of memory",
2461 				  paInsufficientMemory));
2462     return NULL;
2463   }
2464 
2465   Py_BEGIN_ALLOW_THREADS
2466   err = Pa_ReadStream(stream, sampleBlock, total_frames);
2467   Py_END_ALLOW_THREADS
2468 
2469   if (err != paNoError) {
2470 
2471     /* ignore input overflow and output underflow */
2472     if (err & paInputOverflowed) {
2473 
2474 #ifdef VERBOSE
2475       fprintf(stderr, "Input Overflow.\n");
2476 #endif
2477 
2478     } else if (err & paOutputUnderflowed) {
2479 
2480 #ifdef VERBOSE
2481       fprintf(stderr, "Output Underflow.\n");
2482 #endif
2483 
2484     } else {
2485       /* clean up */
2486       _cleanup_Stream_object(streamObject);
2487     }
2488 
2489     /* free the string buffer */
2490     Py_XDECREF(rv);
2491 
2492     PyErr_SetObject(PyExc_IOError,
2493 		    Py_BuildValue("(s,i)",
2494 				  Pa_GetErrorText(err), err));
2495     return NULL;
2496   }
2497 
2498   return rv;
2499 }