File: pyewf_file.c
Function: pyewf_file_read
Error: ob_refcnt of '*result_data' is 1 too high
317  */
318 PyObject* pyewf_file_read(
319            pyewf_file_t *pyewf_file,
320            PyObject *arguments,
321            PyObject *keywords )
322 {
323 	PyObject *result_data       = NULL;
324 	static char *keyword_list[] = {"size", NULL};
325 	int read_size               = -1;
326 	ssize_t read_count          = 0;
327 
328 	if( PyArg_ParseTupleAndKeywords(
when PyArg_ParseTupleAndKeywords() succeeds
taking False path
329 	     arguments,
330 	     keywords,
331 	     "|i",
332 	     keyword_list,
333 	     &read_size ) == 0 )
334 	{
335 		return( NULL );
336 	}
337 	/* Adjust the read size if the size not given or is larger than the size of the media data
338 	 */
339 	if( ( read_size < 0 )
when considering range: -0x80000000 <= value <= -1
taking True path
340 	 || ( pyewf_file->read_offset + (off64_t) read_size ) > (off64_t) pyewf_file->media_size )
341 	{
342 		read_size = pyewf_file->media_size - pyewf_file->read_offset;
343 	}
344 	if( read_size < 0 )
taking False path
345 	{
346 		read_size = 0;
347 	}
348 	/* Make sure the data fits into a memory buffer
349 	 */
350 	if( read_size > INT_MAX )
351 	{
352 		read_size = INT_MAX;
353 	}
354 	result_data = PyString_FromStringAndSize(
when PyString_FromStringAndSize() succeeds
PyStringObject allocated at: 	result_data = PyString_FromStringAndSize(
ob_refcnt is now refs: 1 + N where N >= 0
355 	               NULL,
356 	               read_size );
357 
358 #if defined( HAVE_V2_API )
359 	read_count = libewf_handle_read_buffer(
360 	              pyewf_file->handle,
361 	              PyString_AsString(
362 	               result_data),
363 	              read_size,
364 	              NULL );
365 
366 	if( read_count != (ssize_t) read_size )
367 	{
368 		return( PyErr_Format(
369 		         PyExc_IOError,
370 		         "libewf_handle_read_buffer failed to read data (requested %" PRId32 ", returned %" PRIzd ")",
371 		         read_size,
372 		         read_count ) );
373 	}
374 #else
375 	read_count = libewf_read_buffer(
376 	              pyewf_file->handle,
377 	              PyString_AsString(
PyString_AsString() returns ob_sval
378 	               result_data),
379 	              read_size );
380 
381 	if( read_count != (ssize_t) read_size )
taking True path
382 	{
383 		return( PyErr_Format(
PyErr_Format()
384 		         PyExc_IOError,
385 		         "libewf_read_buffer failed to read data (requested %" PRId32 ", returned %" PRIzd ")",
386 		         read_size,
387 		         read_count ) );
388 	}
389 #endif
390 	pyewf_file->read_offset += read_count;
391 
392 	return( result_data );
393 }
ob_refcnt of '*result_data' 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 2 similar trace(s) to this

File: pyewf_file.c
Function: pyewf_file_read
Error: calling PyString_AsString with NULL as argument 1 (result_data) at pyewf_file.c:377
317  */
318 PyObject* pyewf_file_read(
319            pyewf_file_t *pyewf_file,
320            PyObject *arguments,
321            PyObject *keywords )
322 {
323 	PyObject *result_data       = NULL;
324 	static char *keyword_list[] = {"size", NULL};
325 	int read_size               = -1;
326 	ssize_t read_count          = 0;
327 
328 	if( PyArg_ParseTupleAndKeywords(
when PyArg_ParseTupleAndKeywords() succeeds
taking False path
329 	     arguments,
330 	     keywords,
331 	     "|i",
332 	     keyword_list,
333 	     &read_size ) == 0 )
334 	{
335 		return( NULL );
336 	}
337 	/* Adjust the read size if the size not given or is larger than the size of the media data
338 	 */
339 	if( ( read_size < 0 )
when considering range: -0x80000000 <= value <= -1
taking True path
340 	 || ( pyewf_file->read_offset + (off64_t) read_size ) > (off64_t) pyewf_file->media_size )
341 	{
342 		read_size = pyewf_file->media_size - pyewf_file->read_offset;
343 	}
344 	if( read_size < 0 )
taking False path
345 	{
346 		read_size = 0;
347 	}
348 	/* Make sure the data fits into a memory buffer
349 	 */
350 	if( read_size > INT_MAX )
351 	{
352 		read_size = INT_MAX;
353 	}
354 	result_data = PyString_FromStringAndSize(
when PyString_FromStringAndSize() fails
355 	               NULL,
356 	               read_size );
357 
358 #if defined( HAVE_V2_API )
359 	read_count = libewf_handle_read_buffer(
360 	              pyewf_file->handle,
361 	              PyString_AsString(
362 	               result_data),
363 	              read_size,
364 	              NULL );
365 
366 	if( read_count != (ssize_t) read_size )
367 	{
368 		return( PyErr_Format(
369 		         PyExc_IOError,
370 		         "libewf_handle_read_buffer failed to read data (requested %" PRId32 ", returned %" PRIzd ")",
371 		         read_size,
372 		         read_count ) );
373 	}
374 #else
375 	read_count = libewf_read_buffer(
376 	              pyewf_file->handle,
377 	              PyString_AsString(
calling PyString_AsString with NULL as argument 1 (result_data) at pyewf_file.c:377
PyString_AsString() invokes Py_TYPE() on the pointer via the PyString_Check() macro, thus accessing (NULL)->ob_type
found 2 similar trace(s) to this
378 	               result_data),
379 	              read_size );
380 
381 	if( read_count != (ssize_t) read_size )
382 	{
383 		return( PyErr_Format(
384 		         PyExc_IOError,
385 		         "libewf_read_buffer failed to read data (requested %" PRId32 ", returned %" PRIzd ")",
386 		         read_size,
387 		         read_count ) );
388 	}
389 #endif
390 	pyewf_file->read_offset += read_count;
391 
392 	return( result_data );
393 }