[libunicap] fix some memory errors in the code

Kamil Dudka kdudka at fedoraproject.org
Thu Oct 7 09:47:43 UTC 2010


commit 5b055582d7c82daf9c6860d9c7cc0710ec3364ad
Author: Kamil Dudka <kdudka at redhat.com>
Date:   Thu Oct 7 11:40:34 2010 +0200

    fix some memory errors in the code

 libunicap-0.9.12-arraycmp.patch |   78 +++++++
 libunicap-0.9.12-memerrs.patch  |  137 ++++++++++++
 libunicap-0.9.12-warnings.patch |  433 +++++++++++++++++++++++++++++++++++++++
 libunicap.spec                  |   14 ++-
 4 files changed, 661 insertions(+), 1 deletions(-)
---
diff --git a/libunicap-0.9.12-arraycmp.patch b/libunicap-0.9.12-arraycmp.patch
new file mode 100644
index 0000000..4a38df1
--- /dev/null
+++ b/libunicap-0.9.12-arraycmp.patch
@@ -0,0 +1,78 @@
+From 6cf16e964e312a2e040cc3e7b45be21715961a19 Mon Sep 17 00:00:00 2001
+From: Kamil Dudka <kdudka at redhat.com>
+Date: Thu, 7 Oct 2010 11:02:48 +0200
+Subject: [PATCH 2/2] linunicap: do not compare arrays with NULL
+
+---
+ cpi/vid21394/vid21394_base.c |    2 +-
+ cpi/vid21394/vid21394_cpi.c  |    3 ---
+ src/unicap_helpers.c         |   10 +++++-----
+ 3 files changed, 6 insertions(+), 9 deletions(-)
+
+diff --git a/cpi/vid21394/vid21394_base.c b/cpi/vid21394/vid21394_base.c
+index 464a760..2ba576d 100644
+--- a/cpi/vid21394/vid21394_base.c
++++ b/cpi/vid21394/vid21394_base.c
+@@ -501,7 +501,7 @@ static unicap_status_t _vid21394_send_fcp_command_new( vid21394handle_t vid21394
+ 
+    raw1394handle_t raw1394handle = vid21394handle->raw1394handle;
+ 
+-   nodeid_t nodeid = 	nodeid = 0xffc0 | vid21394handle->node;
++   nodeid_t nodeid = 0xffc0 | vid21394handle->node;
+ 	
+    unicap_status_t status = STATUS_SUCCESS;
+ 
+diff --git a/cpi/vid21394/vid21394_cpi.c b/cpi/vid21394/vid21394_cpi.c
+index e3778e4..738d0d7 100644
+--- a/cpi/vid21394/vid21394_cpi.c
++++ b/cpi/vid21394/vid21394_cpi.c
+@@ -654,7 +654,6 @@ int cpi_enumerate_formats( void *cpi_data, unicap_format_t *format, int index )
+       return STATUS_INVALID_PARAMETER;
+    }
+ 	
+-   if( !data->current_formats )
+    {
+       int tmp;
+       cpi_reenumerate_formats( cpi_data, &tmp );
+@@ -683,7 +682,6 @@ int cpi_set_format( void *cpi_data, unicap_format_t *format )
+ 	
+    TRACE( "cpi_set_format\n" );
+ 
+-   if( !data->current_formats )
+    {
+       int tmp;
+       cpi_reenumerate_formats( cpi_data, &tmp );
+@@ -845,7 +843,6 @@ unicap_status_t cpi_get_format( void *cpi_data, unicap_format_t *format )
+ {
+    vid21394_data_t *data = cpi_data;
+ 
+-   if( !data->current_formats )
+    {
+       int tmp;
+       cpi_reenumerate_formats( cpi_data, &tmp );
+diff --git a/src/unicap_helpers.c b/src/unicap_helpers.c
+index c2e1ec4..67578ac 100644
+--- a/src/unicap_helpers.c
++++ b/src/unicap_helpers.c
+@@ -105,13 +105,13 @@ unicap_status_t unicap_describe_device( unicap_device_t *device, char *buffer, s
+ 		 "Vendor id: %u ( 0x%x )\n"\
+ 		 "cpi: %s\n"\
+ 		 "device: %s\n", 
+-		 device->identifier ? device->identifier : "(nil)",
+-		 device->model_name ? device->model_name : "(nil)", 
+-		 device->vendor_name ? device->vendor_name : "(nil)", 
++		 device->identifier,
++		 device->model_name, 
++		 device->vendor_name, 
+ 		 device->model_id,
+ 		 device->vendor_id, device->vendor_id, 
+-		 device->cpi_layer ? device->cpi_layer : "(nil)", 
+-		 device->device ? device->device : "(nil)" );
++		 device->cpi_layer, 
++		 device->device);
+ 	
+ 	strncpy( buffer, tmp_buffer, (*buffer_size)-1 );
+ 	
+-- 
+1.7.2.3
+
diff --git a/libunicap-0.9.12-memerrs.patch b/libunicap-0.9.12-memerrs.patch
new file mode 100644
index 0000000..44d6993
--- /dev/null
+++ b/libunicap-0.9.12-memerrs.patch
@@ -0,0 +1,137 @@
+From 739d6bde46f6d7dd68e228f2a27eb039d0550999 Mon Sep 17 00:00:00 2001
+From: Kamil Dudka <kdudka at redhat.com>
+Date: Thu, 7 Oct 2010 10:56:06 +0200
+Subject: [PATCH] libunicap: fix various memory errors
+
+---
+ cpi/dcam/dcam_v_modes.c       |    3 ++-
+ cpi/euvccam/euvccam_capture.c |    1 +
+ cpi/v4l/v4l.c                 |    2 +-
+ cpi/v4l2cpi/v4l2.c            |   12 ++++++++++--
+ cpi/vid21394/vid21394_cpi.c   |    5 ++---
+ src/unicap.c                  |    2 ++
+ 6 files changed, 18 insertions(+), 7 deletions(-)
+
+diff --git a/cpi/dcam/dcam_v_modes.c b/cpi/dcam/dcam_v_modes.c
+index 2b8e45a..05dd318 100644
+--- a/cpi/dcam/dcam_v_modes.c
++++ b/cpi/dcam/dcam_v_modes.c
+@@ -182,7 +182,8 @@ unicap_status_t _dcam_prepare_format_array( dcam_handle_t dcamhandle,
+ 		  int index = _dcam_get_mode_index( f, i );
+ 		  TRACE( "f: %d m: %d  index: %d (%s)\n", f, i, index, _dcam_unicap_formats[index].identifier );
+ 		  TRACE( "size: %d x %d\n", _dcam_unicap_formats[index].size.width, _dcam_unicap_formats[index].size.height );
+-		  memcpy( format_array + current_format, &_dcam_unicap_formats[index], sizeof( unicap_format_t ) );
++		  if( 0 < index )
++		     memcpy( format_array + current_format, &_dcam_unicap_formats[index], sizeof( unicap_format_t ) );
+ 		  current_format++;
+ 	       }
+ 	    }
+diff --git a/cpi/euvccam/euvccam_capture.c b/cpi/euvccam/euvccam_capture.c
+index 2909bdb..d4ea60e 100644
+--- a/cpi/euvccam/euvccam_capture.c
++++ b/cpi/euvccam/euvccam_capture.c
+@@ -231,6 +231,7 @@ static void *capture_thread( euvccam_handle_t handle )
+       if( ret < 0 ){
+ 	 TRACE( "Failed to submit urb!\n" );
+ 	 perror( "ioctl" );
++	 free( urb );
+ 	 return NULL;
+       }
+ 
+diff --git a/cpi/v4l/v4l.c b/cpi/v4l/v4l.c
+index 91b7e87..416dc30 100644
+--- a/cpi/v4l/v4l.c
++++ b/cpi/v4l/v4l.c
+@@ -292,7 +292,7 @@ static unicap_status_t v4l_open( void **cpi_data, unicap_device_t *device )
+ 	v4l_handle_t v4lhandle;
+ 	
+ 	*cpi_data = malloc( sizeof( struct _v4l_handle ) );
+-	if( !cpi_data )
++	if( !*cpi_data )
+ 	{
+ 		TRACE( "malloc failed\n" );
+ 		return STATUS_FAILURE;
+diff --git a/cpi/v4l2cpi/v4l2.c b/cpi/v4l2cpi/v4l2.c
+index ba3d5b3..925659c 100644
+--- a/cpi/v4l2cpi/v4l2.c
++++ b/cpi/v4l2cpi/v4l2.c
+@@ -864,7 +864,7 @@ static unicap_status_t v4l2_reenumerate_formats( void *cpi_data, int *_pcount )
+ 
+       sizes = build_format_size_table( handle, v4l2_fmt.pixelformat, &size_count );
+ 		
+-      if( size_count == 0 )
++      if( sizes == NULL )
+       {
+ 	 handle->unicap_formats[v4l2_fmt.index].min_size.width = 
+ 	    handle->unicap_formats[v4l2_fmt.index].min_size.height = 1;
+@@ -927,7 +927,9 @@ static unicap_status_t v4l2_reenumerate_formats( void *cpi_data, int *_pcount )
+ 	 handle->unicap_formats[v4l2_fmt.index].size_count = size_count;
+ 	 handle->unicap_formats[v4l2_fmt.index].buffer_size = 
+ 	    ( sizes[size_count-1].width * sizes[size_count-1].height * handle->unicap_formats[v4l2_fmt.index].bpp / 8 );
+-      } 
++
++	 free( sizes );
++      }
+ 
+       v4l2_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+    }
+@@ -2148,6 +2150,8 @@ static unicap_status_t v4l2_queue_buffer( void *cpi_data, unicap_data_buffer_t *
+       else
+       {
+ 	 TRACE( "queue buffer failed\n" );
++	 free( queue );
++	 /* FIXME: should return STATUS_FAILURE? */
+       }
+ 
+       if( ( status == STATUS_NO_BUFFERS ) && ( buffer->type == UNICAP_BUFFER_TYPE_SYSTEM ) )
+@@ -2155,6 +2159,10 @@ static unicap_status_t v4l2_queue_buffer( void *cpi_data, unicap_data_buffer_t *
+ 	 status = STATUS_SUCCESS;
+       }
+    }
++   else
++   {
++      free( queue );
++   }
+ 
+    
+    return STATUS_SUCCESS;
+diff --git a/cpi/vid21394/vid21394_cpi.c b/cpi/vid21394/vid21394_cpi.c
+index c79e8db..e3778e4 100644
+--- a/cpi/vid21394/vid21394_cpi.c
++++ b/cpi/vid21394/vid21394_cpi.c
+@@ -504,9 +504,6 @@ int cpi_close( void *cpi_data )
+ {
+    vid21394_data_t *data = cpi_data;
+ 
+-   vid21394_close( data->vid21394handle );
+-
+-
+    ucutil_destroy_queue( data->in_queue );
+    ucutil_destroy_queue( data->out_queue );	
+ 	
+@@ -515,6 +512,8 @@ int cpi_close( void *cpi_data )
+       free( data->vid21394handle->unicap_handle );
+    }
+ 
++   vid21394_close( data->vid21394handle );
++
+    g_instance_count--;
+    free( data );
+ 	
+diff --git a/src/unicap.c b/src/unicap.c
+index 5cfa673..f56c6f0 100644
+--- a/src/unicap.c
++++ b/src/unicap.c
+@@ -1521,7 +1521,9 @@ unicap_status_t unicap_data_buffer_unref( unicap_data_buffer_t *buffer )
+ 	 buffer->private->unref_func (buffer, buffer->private->unref_func_data);
+       }
+       if (buffer->private->ref_count == 0 ){
++	 sem_post (&buffer->private->lock);
+ 	 unicap_data_buffer_free( buffer );
++	 return STATUS_SUCCESS;
+       }
+    }else{
+       TRACE( "unref of a buffer with refcount <= 0!" );
+-- 
+1.7.2.3
+
diff --git a/libunicap-0.9.12-warnings.patch b/libunicap-0.9.12-warnings.patch
new file mode 100644
index 0000000..e8daf81
--- /dev/null
+++ b/libunicap-0.9.12-warnings.patch
@@ -0,0 +1,433 @@
+ cpi/dcam/dcam_capture.c         |    8 ----
+ cpi/dcam/dcam_property.c        |    2 -
+ cpi/euvccam/debayer.c           |    5 ---
+ cpi/euvccam/euvccam_colorproc.c |    2 +
+ cpi/euvccam/euvccam_cpi.c       |    2 +
+ cpi/euvccam/euvccam_device.c    |    2 +-
+ cpi/euvccam/euvccam_usb.c       |    1 +
+ cpi/euvccam/logging.c           |    1 +
+ cpi/v4l2cpi/buffermanager.c     |   19 +---------
+ cpi/v4l2cpi/tiseuvccam.c        |    2 +
+ cpi/v4l2cpi/tisuvccam.c         |   31 +---------------
+ cpi/v4l2cpi/v4l2.c              |   74 +--------------------------------------
+ cpi/vid21394/vid21394_base.c    |    3 +-
+ src/unicap_helpers.c            |    2 +-
+ 14 files changed, 16 insertions(+), 138 deletions(-)
+
+diff --git a/cpi/dcam/dcam_capture.c b/cpi/dcam/dcam_capture.c
+index f92f757..068a78f 100644
+--- a/cpi/dcam/dcam_capture.c
++++ b/cpi/dcam/dcam_capture.c
+@@ -60,14 +60,6 @@ static void new_frame_event( dcam_handle_t dcamhandle, unicap_data_buffer_t *buf
+    }
+ }
+ 
+-static void drop_frame_event( dcam_handle_t dcamhandle )
+-{
+-	if( dcamhandle->event_callback )
+-	{
+-		dcamhandle->event_callback( dcamhandle->unicap_handle, UNICAP_EVENT_NEW_FRAME );
+-	}
+-}	
+-
+ static void cleanup_handler( void *arg )
+ {
+ 	TRACE( "cleanup_handler\n" );
+diff --git a/cpi/dcam/dcam_property.c b/cpi/dcam/dcam_property.c
+index 8199162..6bf1dff 100644
+--- a/cpi/dcam/dcam_property.c
++++ b/cpi/dcam/dcam_property.c
+@@ -1017,7 +1017,6 @@ unicap_status_t dcam_init_trigger_property( dcam_handle_t dcamhandle,
+ 	 // TRIGGER_POLARITY
+ 	 if( ( dcam_property->register_inq >> 26 ) & 0x1 )
+ 	 {
+-	    int i;
+ 	    strcpy( dcam_property->unicap_property.menu_item, dcamhandle->trigger_polarities[( dcam_property->register_default >> 26 ) & 1] );
+ 	    dcam_property->unicap_property.menu.menu_item_count = 2;
+ 	    dcam_property->unicap_property.menu.menu_items = dcamhandle->trigger_polarities;
+@@ -1430,7 +1429,6 @@ unicap_status_t dcam_set_property( dcam_handle_t dcamhandle,
+ 
+       case PPTY_TYPE_TRIGGER_POLARITY:
+       {
+-	 int i;
+ 	 quadlet_t quad = 0;
+ 			
+ 	 status = _dcam_read_register( dcamhandle->raw1394handle, 
+diff --git a/cpi/euvccam/debayer.c b/cpi/euvccam/debayer.c
+index 1f0bffc..4e04506 100644
+--- a/cpi/euvccam/debayer.c
++++ b/cpi/euvccam/debayer.c
+@@ -88,7 +88,6 @@ void debayer_calculate_rbgain( unicap_data_buffer_t *buffer, int *rgain, int *bg
+ void debayer_ccm_rgb24_nn( unicap_data_buffer_t *destbuf, unicap_data_buffer_t *srcbuf, debayer_data_t *data )
+ {
+    int i, j;
+-   int dest_offset = 0;
+    unsigned char *dest = destbuf->data;
+    unsigned char *source = srcbuf->data;
+    int width = srcbuf->format.size.width;
+@@ -159,15 +158,12 @@ void debayer_ccm_rgb24_nn( unicap_data_buffer_t *destbuf, unicap_data_buffer_t *
+ void debayer_ccm_rgb24_nn_be( unicap_data_buffer_t *destbuf, unicap_data_buffer_t *srcbuf, debayer_data_t *data )
+ {
+    int i, j;
+-   int dest_offset = 0;
+    unsigned char *dest = destbuf->data;
+    unsigned char *source = srcbuf->data;
+    int width = srcbuf->format.size.width;
+    int height = srcbuf->format.size.height;   
+    int rgain, bgain;
+ 
+-   static int odd = 0;
+-
+    if( data->use_rbgain )
+    {
+       rgain = data->rgain;
+@@ -242,7 +238,6 @@ void debayer_ccm_rgb24_nn_be( unicap_data_buffer_t *destbuf, unicap_data_buffer_
+ void debayer_ccm_rgb24_gr_nn( unicap_data_buffer_t *destbuf, unicap_data_buffer_t *srcbuf, debayer_data_t *data )
+ {
+    int i, j;
+-   int dest_offset = 0;
+    unsigned char *dest = destbuf->data;
+    unsigned char *source = srcbuf->data;
+    int width = srcbuf->format.size.width;
+diff --git a/cpi/euvccam/euvccam_colorproc.c b/cpi/euvccam/euvccam_colorproc.c
+index 807ae65..adf98c3 100644
+--- a/cpi/euvccam/euvccam_colorproc.c
++++ b/cpi/euvccam/euvccam_colorproc.c
+@@ -21,6 +21,8 @@
+ #include "euvccam_cpi.h"
+ #include "debayer.h"
+ 
++#include <string.h>
++
+ void euvccam_colorproc_by8_rgb24_nn( euvccam_handle_t handle, unicap_data_buffer_t *dest, unicap_data_buffer_t *src )
+ {
+ #ifdef __SSE2__
+diff --git a/cpi/euvccam/euvccam_cpi.c b/cpi/euvccam/euvccam_cpi.c
+index 73d413a..8e39343 100644
+--- a/cpi/euvccam/euvccam_cpi.c
++++ b/cpi/euvccam/euvccam_cpi.c
+@@ -94,6 +94,8 @@ static struct _unicap_cpi cpi_s =
+    cpi_set_event_notify: (cpi_set_event_notify_t)euvccam_set_event_notify,
+ };
+ 
++void log_init( void );
++
+ unicap_status_t cpi_register( struct _unicap_cpi *reg_data )
+ {
+    memcpy( reg_data, &cpi_s, sizeof( struct _unicap_cpi ) );
+diff --git a/cpi/euvccam/euvccam_device.c b/cpi/euvccam/euvccam_device.c
+index 73a2be3..7168cdf 100644
+--- a/cpi/euvccam/euvccam_device.c
++++ b/cpi/euvccam/euvccam_device.c
+@@ -788,7 +788,7 @@ unicap_status_t euvccam_device_set_gpout( euvccam_handle_t handle, unicap_proper
+    unicap_status_t status = STATUS_SUCCESS;
+    unsigned char val = (property->flags & UNICAP_FLAGS_ON_OFF)?1:0;
+    
+-   printf( "%lld %d\n", property->flags, val );
++   printf( "%lld %d\n", (long long int) property->flags, val );
+ 
+    status = euvccam_usb_ctrl_msg( handle->dev.fd, 
+ 				  EP0_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, 
+diff --git a/cpi/euvccam/euvccam_usb.c b/cpi/euvccam/euvccam_usb.c
+index 4059c9e..fcff74b 100644
+--- a/cpi/euvccam/euvccam_usb.c
++++ b/cpi/euvccam/euvccam_usb.c
+@@ -24,6 +24,7 @@
+ #include <fcntl.h>
+ #include <sys/ioctl.h>
+ #include <unicap.h>
++#include <stdio.h>
+ #include <stdint.h>
+ #include <string.h>
+ #include <linux/usbdevice_fs.h>
+diff --git a/cpi/euvccam/logging.c b/cpi/euvccam/logging.c
+index 065501e..7b98daa 100644
+--- a/cpi/euvccam/logging.c
++++ b/cpi/euvccam/logging.c
+@@ -21,6 +21,7 @@
+ #include <stdlib.h>
+ #include <stdio.h>
+ #include <stdarg.h>
++#include <string.h>
+ 
+ FILE *g_logfp = NULL;
+ int g_log_modules_mask = 0xffff;
+diff --git a/cpi/v4l2cpi/buffermanager.c b/cpi/v4l2cpi/buffermanager.c
+index 7c0cbae..9a07ffc 100644
+--- a/cpi/v4l2cpi/buffermanager.c
++++ b/cpi/v4l2cpi/buffermanager.c
+@@ -11,6 +11,8 @@
+ #include <errno.h>
+ #include <sys/mman.h>
+ 
++#include <libv4l2.h>
++
+ #if V4L2_DEBUG
+ #define DEBUG
+ #endif
+@@ -60,8 +62,6 @@ struct buffer_mgr
+ 
+ #define BUFFER_MGR_UNLOCK(mgr) { sem_post( &mgr->lock); }
+ 
+-static v4l2cpi_buffer_t *buffer_mgr_get_cpi_buffer( buffer_mgr_t mgr, unicap_data_buffer_t *buffer );
+-
+ 
+ static void v4l2_data_buffer_unref( unicap_data_buffer_t *buffer, buffer_mgr_t mgr )
+ {
+@@ -167,21 +167,6 @@ void buffer_mgr_destroy( buffer_mgr_t mgr )
+ }
+ 
+ 
+-static v4l2cpi_buffer_t *buffer_mgr_get_cpi_buffer( buffer_mgr_t mgr, unicap_data_buffer_t *buffer )
+-{
+-   int i;
+-   
+-   for( i = 0; i < mgr->num_buffers; i++ ){
+-      if (&mgr->buffers[i].data_buffer == buffer){
+-	 return &mgr->buffers[i];
+-      }
+-   }
+-
+-   return NULL;
+-}
+-
+-   
+-
+ unicap_status_t buffer_mgr_queue_all( buffer_mgr_t mgr )
+ {
+    int i;
+diff --git a/cpi/v4l2cpi/tiseuvccam.c b/cpi/v4l2cpi/tiseuvccam.c
+index 93729a5..b7d1e1b 100644
+--- a/cpi/v4l2cpi/tiseuvccam.c
++++ b/cpi/v4l2cpi/tiseuvccam.c
+@@ -22,6 +22,8 @@
+ #include <fcntl.h>
+ #include <linux/videodev2.h>
+ 
++#include <libv4l2.h>
++
+ #include "uvc_compat.h"
+ 
+ #if V4L2_DEBUG
+diff --git a/cpi/v4l2cpi/tisuvccam.c b/cpi/v4l2cpi/tisuvccam.c
+index 62ee147..207ff4c 100644
+--- a/cpi/v4l2cpi/tisuvccam.c
++++ b/cpi/v4l2cpi/tisuvccam.c
+@@ -15,6 +15,8 @@
+ #include <fcntl.h>
+ #include <string.h>
+ 
++#include <libv4l2.h>
++
+ #include "uvcvideo.h"
+ 
+ #if V4L2_DEBUG
+@@ -358,18 +360,6 @@ static struct ppty_info TISUVCPropertyOverrides[] =
+    }
+ };
+ 
+-static struct uvc_format TISUVCFormats[] =
+-{
+-   {
+-      type: V4L2_BUF_TYPE_VIDEO_CAPTURE, 
+-      bpp: 8, 
+-      colorspace: 0, 
+-      fcc: FOURCC( 'Y', '8', '0', '0' ), 
+-      flags: 0,
+-      name: "30303859-0000-0010-8000-00aa003", 
+-   }
+-};
+-      
+ static void tisuvccam_add_controls( int fd )
+ {
+    int i; 
+@@ -404,21 +394,6 @@ static void tisuvccam_add_controls( int fd )
+    }
+ }
+ 
+-static void tisuvccam_add_formats( int fd )
+-{
+-/*    int i; */
+-/*    int n = sizeof( TISUVCFormats ) / sizeof( struct uvc_format ); */
+-   
+-/*    for( i = 0; i < n; i++ ) */
+-/*    { */
+-/*       if( ioctl( fd, UVCIOC_FMT_SET, &TISUVCFormats[i] ) < 0 ) */
+-/*       { */
+-/* 	 TRACE( "Failed to set format info for %d\n", i ); */
+-/*       } */
+-/*    } */
+-}
+-
+-
+ 
+ int tisuvccam_probe( v4l2_handle_t handle, const char *path )
+ {
+@@ -661,8 +636,6 @@ unicap_status_t tisuvccam_set_property( v4l2_handle_t handle, unicap_property_t
+    {
+       case XU_AUTO_SHUTTER_MAX:
+       {
+-	 struct uvc_xu_control autoctrl;
+-	 __u8 u8data;
+ 	 
+ 	 /* u8data = ( property->flags & UNICAP_FLAGS_AUTO ) ? 1 : 0; */
+ 	    
+diff --git a/cpi/v4l2cpi/v4l2.c b/cpi/v4l2cpi/v4l2.c
+index 925659c..a8e0c92 100644
+--- a/cpi/v4l2cpi/v4l2.c
++++ b/cpi/v4l2cpi/v4l2.c
+@@ -252,7 +252,6 @@ static unicap_status_t v4l2_set_event_notify( void *cpi_data,
+ 					      unicap_handle_t unicap_handle );
+ 
+ static unicap_status_t queue_buffer( v4l2_handle_t handle, unicap_data_buffer_t *buffer );
+-static unicap_status_t queue_system_buffers( v4l2_handle_t handle );
+ static void v4l2_capture_thread( v4l2_handle_t handle );
+ 
+ static struct _unicap_cpi cpi_s = 
+@@ -1440,7 +1439,7 @@ static unicap_status_t add_properties_ext( v4l2_handle_t handle, int *ppty_index
+    int ret;
+    
+    v4l2ctrl.id = V4L2_CTRL_FLAG_NEXT_CTRL;
+-   while( ret = IOCTL( handle->fd, VIDIOC_QUERYCTRL, &v4l2ctrl ) == 0 )
++   while(( ret = IOCTL( handle->fd, VIDIOC_QUERYCTRL, &v4l2ctrl ) == 0 ))
+    {
+ 	 TRACE( "++%s++\n", v4l2ctrl.name );
+ 
+@@ -1918,7 +1917,6 @@ static unicap_status_t v4l2_get_property( void *cpi_data, unicap_property_t *pro
+ static unicap_status_t v4l2_capture_start( void *cpi_data )
+ {
+    v4l2_handle_t handle = (v4l2_handle_t) cpi_data;
+-   struct v4l2_requestbuffers v4l2_reqbuf;
+ 
+    unicap_status_t status = STATUS_SUCCESS;
+ 
+@@ -1952,7 +1950,6 @@ static unicap_status_t v4l2_capture_stop( void *cpi_data )
+    v4l2_handle_t handle = (v4l2_handle_t) cpi_data;
+    
+    int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+-   int i;
+ 
+    TRACE( "v4l2_capture_stop\n" );
+ 
+@@ -2069,69 +2066,6 @@ static unicap_status_t queue_buffer( v4l2_handle_t handle, unicap_data_buffer_t
+    return STATUS_SUCCESS;
+ }
+ 
+-static unicap_status_t queue_system_buffers( v4l2_handle_t handle )
+-{
+-   struct v4l2_buffer v4l2_buffer;
+-   memset( &v4l2_buffer, 0x0, sizeof( v4l2_buffer ) );
+-   v4l2_buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+-   v4l2_buffer.length = handle->current_format.buffer_size;
+-   switch( handle->io_method )
+-   {
+-      case CPI_V4L2_IO_METHOD_MMAP:
+-      {
+-	 int i;
+-	 v4l2_buffer.index = 0;
+-	 v4l2_buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+-	 v4l2_buffer.memory = V4L2_MEMORY_MMAP;
+-
+-	 if( sem_wait( &handle->sema ) )
+-	 {
+-	    TRACE( "SEM_WAIT FAILED!\n" );
+-	    return STATUS_FAILURE;
+-	 }
+-		
+-	 for( i = 0; i < handle->buffer_count; i++ )
+-	 {
+-	    int ret;
+-	    if( ( ( handle->qindex + 1 ) % handle->buffer_count ) == handle->dqindex )
+-	    {
+-	       TRACE( "NO BUFFERS\n" );
+-	       sem_post( &handle->sema );
+-	       return STATUS_NO_BUFFERS;
+-	    }
+-
+-	    v4l2_buffer.index = handle->qindex;
+-	    TRACE( "Q: index = %d type = %u, memory = %u  dqindex = %d\n", handle->qindex, v4l2_buffer.type, v4l2_buffer.memory, handle->dqindex );
+-	    handle->qindex = ( handle->qindex + 1 ) % handle->buffer_count;
+-	    v4l2_buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+-
+-	    if( ( ret = IOCTL( handle->fd, VIDIOC_QBUF, &v4l2_buffer ) ) < 0 )
+-	    {
+-	       if( ( ret == -ENODEV ) && !handle->removed && handle->event_callback )
+-	       {
+-		  handle->event_callback( handle->unicap_handle, UNICAP_EVENT_DEVICE_REMOVED );
+-		  handle->removed = 1;
+-	       }
+-	       TRACE( "VIDIOC_QBUF ioctl failed: %s\n", strerror( errno ) );
+-	       sem_post( &handle->sema );
+-	       return STATUS_FAILURE;
+-	    }
+-
+-	    if( sem_post( &handle->sema ) )
+-	    {
+-	       TRACE( "SEM_POST FAILED\n" );
+-	       return STATUS_FAILURE;
+-	    }  
+-	 }
+-      }
+-      break;
+-      default:
+-	 return STATUS_FAILURE;
+-   }
+-
+-   return STATUS_SUCCESS;
+-}
+-
+ static unicap_status_t v4l2_queue_buffer( void *cpi_data, unicap_data_buffer_t *buffer )
+ {
+    v4l2_handle_t handle = (v4l2_handle_t) cpi_data;
+@@ -2231,17 +2165,11 @@ static unicap_status_t v4l2_set_event_notify( void *cpi_data, unicap_event_callb
+ 
+ static void v4l2_capture_thread( v4l2_handle_t handle )
+ {
+-   unicap_data_buffer_t new_frame_buffer;
+-
+    handle->dqindex = -1;
+ 
+    while( !handle->quit_capture_thread )
+    {
+-      unicap_queue_t *entry;
+-      struct timeval  ctime;
+-      int old_index;
+       int drop = 0;
+-      int ret = 0;
+ 
+       unicap_data_buffer_t *data_buffer;
+       
+diff --git a/cpi/vid21394/vid21394_base.c b/cpi/vid21394/vid21394_base.c
+index 2ba576d..8339845 100644
+--- a/cpi/vid21394/vid21394_base.c
++++ b/cpi/vid21394/vid21394_base.c
+@@ -1333,7 +1333,7 @@ unicap_status_t vid21394_rs232_io( vid21394handle_t vid21394handle,
+ 	
+ /*    TRACE( "rs232io fcp: %08llx out_data_length: %d, in_data_length: %d\n", fcp, out_data_length, in_data_length ); */
+ 
+-   return( _vid21394_send_fcp_command_new( vid21394handle, fcp, bit, out_data, out_data_length, in_data, (unsigned int *)&in_data_length ) );
++   return( _vid21394_send_fcp_command_new( vid21394handle, fcp, bit, out_data, out_data_length, in_data, (size_t *)&in_data_length ) );
+ }
+ 
+ unicap_status_t vid21394_read_rs232( vid21394handle_t vid21394handle, 
+@@ -1629,7 +1629,6 @@ int vid21394_wait_buffer( vid21394handle_t vid21394handle, void **buffer )
+ */
+ int vid21394_poll_buffer( vid21394handle_t vid21394handle )
+ {
+-   int buffers = 0;
+ /*    unicap_queue_t *entry = &vid21394handle->ready_buffers; */
+ 
+ /*    while( entry->next ) */
+diff --git a/src/unicap_helpers.c b/src/unicap_helpers.c
+index 67578ac..ae73f5a 100644
+--- a/src/unicap_helpers.c
++++ b/src/unicap_helpers.c
+@@ -292,7 +292,7 @@ unicap_status_t unicap_describe_property( unicap_property_t *property, char *buf
+ 		 property->range.min,
+ 		 property->range.max,
+ 		 property->stepping,
+-		 property->property_data_size );
++		 (int) property->property_data_size );
+ 	
+ 	strncpy( buffer, tmp_buffer, *buffer_size );
+ 	
diff --git a/libunicap.spec b/libunicap.spec
index a38f15c..27f2f82 100644
--- a/libunicap.spec
+++ b/libunicap.spec
@@ -7,13 +7,16 @@
 Summary:	Library to access different kinds of (video) capture devices
 Name:		libunicap
 Version:	0.9.12
-Release:	1%{?dist}
+Release:	2%{?dist}
 License:	GPLv2+
 Group:		System Environment/Libraries
 URL:		http://www.unicap-imaging.org/
 Source0:	http://www.unicap-imaging.org/downloads/%{name}-%{version}.tar.gz
 Source1:	%{name}-filter.sh
 Patch0:		libunicap-0.9.12-includes.patch
+Patch1:		libunicap-0.9.12-memerrs.patch
+Patch2:		libunicap-0.9.12-arraycmp.patch
+Patch3:		libunicap-0.9.12-warnings.patch
 BuildRequires:	intltool, /usr/bin/perl, perl(XML::Parser), gettext, gtk-doc >= 1.4
 %ifnarch s390 s390x
 BuildRequires:	libraw1394-devel >= 1.1.0
@@ -46,6 +49,9 @@ API documentation of the library, too.
 %prep
 %setup -q
 %patch0 -p1 -b .includes
+%patch1 -p1
+%patch2 -p1
+%patch3 -p1
 
 # Needed to get rid of rpath
 %if 0%{?rhel}%{?fedora} >= 6
@@ -59,6 +65,7 @@ autoreconf --force --install
 %else
 %configure --disable-rpath --enable-gtk-doc
 %endif
+make %{?_smp_mflags}
 
 %install
 rm -rf $RPM_BUILD_ROOT
@@ -91,6 +98,11 @@ rm -rf $RPM_BUILD_ROOT
 %{_datadir}/gtk-doc/html/%{name}
 
 %changelog
+* Thu Oct 07 2010 Kamil Dudka <kdudka at redhat.com> 0.9.12-2
+- build the package in %%build
+- fix tons of compile-time warnings
+- fix some memory errors in the code
+
 * Mon Oct 04 2010 Robert Scheck <robert at fedoraproject.org> 0.9.12-1
 - Upgrade to 0.9.12 (#635377)
 


More information about the scm-commits mailing list