Commit 387950f7 authored by Rémi Duraffort's avatar Rémi Duraffort

Fix a memory leak.

Test for the right thing before tring to do anything.
Check malloc return value (fix potential segfault).
parent ead25bd0
...@@ -611,30 +611,33 @@ static void UpdateBookmarksOption( input_thread_t *p_input ) ...@@ -611,30 +611,33 @@ static void UpdateBookmarksOption( input_thread_t *p_input )
char *psz_value = NULL, *psz_next = NULL; char *psz_value = NULL, *psz_next = NULL;
vlc_mutex_lock( &p_input->p->input.p_item->lock ); 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"}", for( i = 0; i < p_input->p->i_bookmark; i++ )
p_input->p->bookmark[i]->psz_name, {
p_input->p->bookmark[i]->i_byte_offset, i_len += snprintf( NULL, 0, "{name=%s,bytes=%"PRId64",time=%"PRId64"}",
p_input->p->bookmark[i]->i_time_offset/1000000 ); p_input->p->bookmark[i]->psz_name,
} p_input->p->bookmark[i]->i_byte_offset,
for( i = 0; i < p_input->p->i_bookmark; i++ ) p_input->p->bookmark[i]->i_time_offset/1000000 );
{ }
if( !i ) psz_value = psz_next = malloc( i_len + p_input->p->i_bookmark ); 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 );
psz_next += strlen( psz_next ); for( i = 0; i < p_input->p->i_bookmark; i++ )
if( i < p_input->p->i_bookmark - 1)
{ {
*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 ); vlc_mutex_unlock( &p_input->p->input.p_item->lock );
input_Control( p_input, INPUT_ADD_OPTION, "bookmarks", input_Control( p_input, INPUT_ADD_OPTION, "bookmarks",
psz_value ? psz_value : "" ); psz_value ? psz_value : "" );
free( psz_value );
} }
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