Commit f52a5055 authored by Rafaël Carré's avatar Rafaël Carré

vcd ioctl_ReadSectors() : factorize error case

parent ebab71b5
...@@ -506,16 +506,14 @@ int ioctl_ReadSectors( vlc_object_t *p_this, const vcddev_t *p_vcddev, ...@@ -506,16 +506,14 @@ int ioctl_ReadSectors( vlc_object_t *p_this, const vcddev_t *p_vcddev,
SEEK_SET ) == -1 ) SEEK_SET ) == -1 )
{ {
msg_Err( p_this, "Could not lseek to sector %d", i_sector ); msg_Err( p_this, "Could not lseek to sector %d", i_sector );
if( i_type == VCD_TYPE ) free( p_block ); goto error;
return -1;
} }
if( read( p_vcddev->i_vcdimage_handle, p_block, VCD_SECTOR_SIZE * i_nb) if( read( p_vcddev->i_vcdimage_handle, p_block, VCD_SECTOR_SIZE * i_nb)
== -1 ) == -1 )
{ {
msg_Err( p_this, "Could not read sector %d", i_sector ); msg_Err( p_this, "Could not read sector %d", i_sector );
if( i_type == VCD_TYPE ) free( p_block ); goto error;
return -1;
} }
} }
...@@ -543,8 +541,7 @@ int ioctl_ReadSectors( vlc_object_t *p_this, const vcddev_t *p_vcddev, ...@@ -543,8 +541,7 @@ int ioctl_ReadSectors( vlc_object_t *p_this, const vcddev_t *p_vcddev,
if( ioctl( p_vcddev->i_device_handle, DKIOCCDREAD, &cd_read ) == -1 ) if( ioctl( p_vcddev->i_device_handle, DKIOCCDREAD, &cd_read ) == -1 )
{ {
msg_Err( p_this, "could not read block %d", i_sector ); msg_Err( p_this, "could not read block %d", i_sector );
if( i_type == VCD_TYPE ) free( p_block ); goto error;
return -1;
} }
#elif defined( WIN32 ) #elif defined( WIN32 )
...@@ -570,10 +567,7 @@ int ioctl_ReadSectors( vlc_object_t *p_this, const vcddev_t *p_vcddev, ...@@ -570,10 +567,7 @@ int ioctl_ReadSectors( vlc_object_t *p_this, const vcddev_t *p_vcddev,
sizeof(RAW_READ_INFO), p_block, sizeof(RAW_READ_INFO), p_block,
VCD_SECTOR_SIZE * i_nb, &dwBytesReturned, VCD_SECTOR_SIZE * i_nb, &dwBytesReturned,
NULL ) == 0 ) NULL ) == 0 )
{ goto error;
free( p_block );
return -1;
}
} }
else return -1; else return -1;
} }
...@@ -595,11 +589,7 @@ int ioctl_ReadSectors( vlc_object_t *p_this, const vcddev_t *p_vcddev, ...@@ -595,11 +589,7 @@ int ioctl_ReadSectors( vlc_object_t *p_this, const vcddev_t *p_vcddev,
if( rc ) if( rc )
{ {
msg_Err( p_this, "could not read block %d", i_sector ); msg_Err( p_this, "could not read block %d", i_sector );
goto error;
if( i_type == VCD_TYPE )
free( p_block );
return -1;
} }
#elif defined( HAVE_SCSIREQ_IN_SYS_SCSIIO_H ) #elif defined( HAVE_SCSIREQ_IN_SYS_SCSIIO_H )
...@@ -630,15 +620,13 @@ int ioctl_ReadSectors( vlc_object_t *p_this, const vcddev_t *p_vcddev, ...@@ -630,15 +620,13 @@ int ioctl_ReadSectors( vlc_object_t *p_this, const vcddev_t *p_vcddev,
if( i_ret == -1 ) if( i_ret == -1 )
{ {
msg_Err( p_this, "SCIOCCOMMAND failed" ); msg_Err( p_this, "SCIOCCOMMAND failed" );
if( i_type == VCD_TYPE ) free( p_block ); goto error;
return -1;
} }
if( sc.retsts || sc.error ) if( sc.retsts || sc.error )
{ {
msg_Err( p_this, "SCSI command failed: status %d error %d", msg_Err( p_this, "SCSI command failed: status %d error %d",
sc.retsts, sc.error ); sc.retsts, sc.error );
if( i_type == VCD_TYPE ) free( p_block ); goto error;
return -1;
} }
#elif defined( HAVE_IOC_TOC_HEADER_IN_SYS_CDIO_H ) #elif defined( HAVE_IOC_TOC_HEADER_IN_SYS_CDIO_H )
...@@ -648,24 +636,21 @@ int ioctl_ReadSectors( vlc_object_t *p_this, const vcddev_t *p_vcddev, ...@@ -648,24 +636,21 @@ int ioctl_ReadSectors( vlc_object_t *p_this, const vcddev_t *p_vcddev,
== -1 ) == -1 )
{ {
msg_Err( p_this, "Could not set block size" ); msg_Err( p_this, "Could not set block size" );
if( i_type == VCD_TYPE ) free( p_block ); goto error;
return( -1 );
} }
if( lseek( p_vcddev->i_device_handle, if( lseek( p_vcddev->i_device_handle,
i_sector * VCD_SECTOR_SIZE, SEEK_SET ) == -1 ) i_sector * VCD_SECTOR_SIZE, SEEK_SET ) == -1 )
{ {
msg_Err( p_this, "Could not lseek to sector %d", i_sector ); msg_Err( p_this, "Could not lseek to sector %d", i_sector );
if( i_type == VCD_TYPE ) free( p_block ); goto error;
return( -1 );
} }
if( read( p_vcddev->i_device_handle, if( read( p_vcddev->i_device_handle,
p_block, VCD_SECTOR_SIZE * i_nb ) == -1 ) p_block, VCD_SECTOR_SIZE * i_nb ) == -1 )
{ {
msg_Err( p_this, "Could not read sector %d", i_sector ); msg_Err( p_this, "Could not read sector %d", i_sector );
if( i_type == VCD_TYPE ) free( p_block ); goto error;
return( -1 );
} }
#else #else
...@@ -686,11 +671,9 @@ int ioctl_ReadSectors( vlc_object_t *p_this, const vcddev_t *p_vcddev, ...@@ -686,11 +671,9 @@ int ioctl_ReadSectors( vlc_object_t *p_this, const vcddev_t *p_vcddev,
i_sector ); i_sector );
if( i == 0 ) if( i == 0 )
{ goto error;
if( i_type == VCD_TYPE ) free( p_block ); else
return( -1 ); break;
}
else break;
} }
} }
#endif #endif
...@@ -710,6 +693,11 @@ int ioctl_ReadSectors( vlc_object_t *p_this, const vcddev_t *p_vcddev, ...@@ -710,6 +693,11 @@ int ioctl_ReadSectors( vlc_object_t *p_this, const vcddev_t *p_vcddev,
} }
return( 0 ); return( 0 );
error:
if( i_type == VCD_TYPE )
free( p_block );
return( -1 );
} }
/**************************************************************************** /****************************************************************************
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment