|
From: libvidcap c. m. <lib...@li...> - 2007-10-10 18:04:28
|
Revision: 44
http://libvidcap.svn.sourceforge.net/libvidcap/?rev=44&view=rev
Author: bcholew
Date: 2007-10-10 11:04:18 -0700 (Wed, 10 Oct 2007)
Log Message:
-----------
Prevent reference to sliding window of frame_times while processing a residual capture callback (after capture has been stopped and callback structures have been freed). Plug leak: if capture start fails, destroy sliding window of frame_times. Ensure sliding window (yes, frame_times) is destroyed when source is released. Return unique error code if capture fails due to incorrect source state.
Modified Paths:
--------------
trunk/src/sapi.c
trunk/src/vidcap.c
Modified: trunk/src/sapi.c
===================================================================
--- trunk/src/sapi.c 2007-10-09 16:28:27 UTC (rev 43)
+++ trunk/src/sapi.c 2007-10-10 18:04:18 UTC (rev 44)
@@ -92,17 +92,23 @@
{
struct timeval tv_earliest_next;
struct timeval tv_now;
- struct timeval *tv_oldest;
- const int first_time = !sliding_window_count(src_ctx->frame_times);
+ struct timeval *tv_oldest = 0;
+ int first_time = 0;
+ if ( !src_ctx->frame_times )
+ return 0;
+
+ first_time = !sliding_window_count(src_ctx->frame_times);
+
if ( gettimeofday(&tv_now, 0) )
return -1;
if ( !first_time && !tv_greater_or_equal(
&tv_now, &src_ctx->frame_time_next) )
- /* Allow frame through */
return 0;
+ /* Allow frame through */
+
tv_oldest = sliding_window_peek_front(src_ctx->frame_times);
if ( !tv_oldest )
@@ -217,9 +223,9 @@
{
struct vidcap_capture_info cap_info;
- /* NOTE: We may be called here by a notification thread while the
- * main thread is clearing capture_data and capture_callback from
- * within vidcap_src_capture_stop().
+ /* NOTE: We may be called here by the capture thread while the
+ * main thread is clearing capture_data and capture_callback
+ * from within vidcap_src_capture_stop().
*/
vidcap_src_capture_callback cap_callback = src_ctx->capture_callback;
void * cap_data = src_ctx->capture_data;
Modified: trunk/src/vidcap.c
===================================================================
--- trunk/src/vidcap.c 2007-10-09 16:28:27 UTC (rev 43)
+++ trunk/src/vidcap.c 2007-10-10 18:04:18 UTC (rev 44)
@@ -356,6 +356,9 @@
if ( src_ctx->fmt_conv_buf )
free(src_ctx->fmt_conv_buf);
+ if ( src_ctx->frame_times )
+ sliding_window_destroy(src_ctx->frame_times);
+
free(src_ctx);
return ret;
@@ -476,7 +479,7 @@
return -3;
if ( src_ctx->src_state != src_bound )
- return -1;
+ return -4;
src_ctx->frame_time_next.tv_sec = 0;
src_ctx->frame_time_next.tv_usec = 0;
@@ -495,6 +498,8 @@
{
src_ctx->capture_callback = 0;
src_ctx->capture_data = VIDCAP_INVALID_USER_DATA;
+ sliding_window_destroy(src_ctx->frame_times);
+ src_ctx->frame_times = 0;
return ret;
}
@@ -511,14 +516,14 @@
if ( src_ctx->src_state != src_capturing )
return -1;
- src_ctx->src_state = src_bound;
-
ret = src_ctx->stop_capture(src_ctx);
sliding_window_destroy(src_ctx->frame_times);
+ src_ctx->frame_times = 0;
src_ctx->capture_callback = 0;
src_ctx->capture_data = VIDCAP_INVALID_USER_DATA;
+ src_ctx->src_state = src_bound;
return ret;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|