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,6 +611,8 @@ static void UpdateBookmarksOption( input_thread_t *p_input ) ...@@ -611,6 +611,8 @@ 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 );
if( p_input->p->i_bookmark > 0 )
{
for( i = 0; i < p_input->p->i_bookmark; i++ ) for( i = 0; i < p_input->p->i_bookmark; i++ )
{ {
i_len += snprintf( NULL, 0, "{name=%s,bytes=%"PRId64",time=%"PRId64"}", i_len += snprintf( NULL, 0, "{name=%s,bytes=%"PRId64",time=%"PRId64"}",
...@@ -618,10 +620,10 @@ static void UpdateBookmarksOption( input_thread_t *p_input ) ...@@ -618,10 +620,10 @@ static void UpdateBookmarksOption( input_thread_t *p_input )
p_input->p->bookmark[i]->i_byte_offset, p_input->p->bookmark[i]->i_byte_offset,
p_input->p->bookmark[i]->i_time_offset/1000000 ); p_input->p->bookmark[i]->i_time_offset/1000000 );
} }
psz_value = psz_next = malloc( i_len + p_input->p->i_bookmark );
for( i = 0; i < p_input->p->i_bookmark; i++ ) 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"}", sprintf( psz_next, "{name=%s,bytes=%"PRId64",time=%"PRId64"}",
p_input->p->bookmark[i]->psz_name, p_input->p->bookmark[i]->psz_name,
p_input->p->bookmark[i]->i_byte_offset, p_input->p->bookmark[i]->i_byte_offset,
...@@ -629,7 +631,6 @@ static void UpdateBookmarksOption( input_thread_t *p_input ) ...@@ -629,7 +631,6 @@ static void UpdateBookmarksOption( input_thread_t *p_input )
psz_next += strlen( psz_next ); psz_next += strlen( psz_next );
if( i < p_input->p->i_bookmark - 1) if( i < p_input->p->i_bookmark - 1)
{
*psz_next = ','; psz_next++; *psz_next = ','; psz_next++;
} }
} }
...@@ -637,4 +638,6 @@ static void UpdateBookmarksOption( input_thread_t *p_input ) ...@@ -637,4 +638,6 @@ static void UpdateBookmarksOption( input_thread_t *p_input )
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