[vlc-devel] commit: Fix a memory leak. ( Rémi Duraffort )
git version control
git at videolan.org
Mon Jul 14 16:08:57 CEST 2008
vlc | branch: master | Rémi Duraffort <ivoire at videolan.org> | Sat Jul 12 10:44:22 2008 +0200| [387950f7f7ae3768bc39f9487e9559179df325b6]
Fix a memory leak.
Test for the right thing before tring to do anything.
Check malloc return value (fix potential segfault).
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=387950f7f7ae3768bc39f9487e9559179df325b6
---
src/input/control.c | 37 ++++++++++++++++++++-----------------
1 files changed, 20 insertions(+), 17 deletions(-)
diff --git a/src/input/control.c b/src/input/control.c
index d29229a..061d8cc 100644
--- a/src/input/control.c
+++ b/src/input/control.c
@@ -611,30 +611,33 @@ static void UpdateBookmarksOption( input_thread_t *p_input )
char *psz_value = NULL, *psz_next = NULL;
vlc_mutex_lock( &p_input->p->input.p_item->lock );
- for( i = 0; i < p_input->p->i_bookmark; i++ )
+ if( p_input->p->i_bookmark > 0 )
{
- i_len += snprintf( NULL, 0, "{name=%s,bytes=%"PRId64",time=%"PRId64"}",
- p_input->p->bookmark[i]->psz_name,
- p_input->p->bookmark[i]->i_byte_offset,
- p_input->p->bookmark[i]->i_time_offset/1000000 );
- }
- for( i = 0; i < p_input->p->i_bookmark; i++ )
- {
- if( !i ) psz_value = psz_next = malloc( i_len + p_input->p->i_bookmark );
-
- sprintf( psz_next, "{name=%s,bytes=%"PRId64",time=%"PRId64"}",
- p_input->p->bookmark[i]->psz_name,
- p_input->p->bookmark[i]->i_byte_offset,
- p_input->p->bookmark[i]->i_time_offset/1000000 );
+ for( i = 0; i < p_input->p->i_bookmark; i++ )
+ {
+ i_len += snprintf( NULL, 0, "{name=%s,bytes=%"PRId64",time=%"PRId64"}",
+ p_input->p->bookmark[i]->psz_name,
+ p_input->p->bookmark[i]->i_byte_offset,
+ p_input->p->bookmark[i]->i_time_offset/1000000 );
+ }
+ psz_value = psz_next = malloc( i_len + p_input->p->i_bookmark );
- psz_next += strlen( psz_next );
- if( i < p_input->p->i_bookmark - 1)
+ for( i = 0; i < p_input->p->i_bookmark; i++ )
{
- *psz_next = ','; psz_next++;
+ sprintf( psz_next, "{name=%s,bytes=%"PRId64",time=%"PRId64"}",
+ p_input->p->bookmark[i]->psz_name,
+ p_input->p->bookmark[i]->i_byte_offset,
+ p_input->p->bookmark[i]->i_time_offset/1000000 );
+
+ psz_next += strlen( psz_next );
+ if( i < p_input->p->i_bookmark - 1)
+ *psz_next = ','; psz_next++;
}
}
vlc_mutex_unlock( &p_input->p->input.p_item->lock );
input_Control( p_input, INPUT_ADD_OPTION, "bookmarks",
psz_value ? psz_value : "" );
+ free( psz_value );
}
+
More information about the vlc-devel
mailing list