[vlc-commits] [Git][videolan/vlc][3.0.x] 4 commits: lib:media_list_player: add missing nullability checks
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Thu Sep 7 14:49:44 UTC 2023
Felix Paul Kühne pushed to branch 3.0.x at VideoLAN / VLC
Commits:
95f79c82 by Felix Paul Kühne at 2023-09-07T13:34:32+00:00
lib:media_list_player: add missing nullability checks
- - - - -
dc2242c0 by Thomas Guillem at 2023-09-07T13:34:32+00:00
lib: media_list: fix leak
Signed-off-by: Felix Paul Kühne <felix at feepk.net>
- - - - -
4e4e389c by Thomas Guillem at 2023-09-07T13:34:32+00:00
lib: media_list_player: check set_current_playing_item() return
This will allow to fix a leak by only checking the return code instead
of fetching the media (and forgetting to release it...)
Signed-off-by: Felix Paul Kühne <felix at feepk.net>
- - - - -
56529098 by Thomas Guillem at 2023-09-07T13:34:32+00:00
lib: media_list_player: fix leaks
Signed-off-by: Felix Paul Kühne <felix at feepk.net>
- - - - -
2 changed files:
- lib/media_list_path.h
- lib/media_list_player.c
Changes:
=====================================
lib/media_list_path.h
=====================================
@@ -123,8 +123,13 @@ get_path_rec( const libvlc_media_list_path_t path, libvlc_media_list_t * p_curre
{
libvlc_media_t * p_md = libvlc_media_list_item_at_index( p_current_mlist, i );
- if( p_md == p_searched_md )
+ if( !p_md )
+ return NULL;
+
+ if( p_md == p_searched_md ) {
+ libvlc_media_release( p_md );
return libvlc_media_list_path_copy_by_appending( path, i ); /* Found! */
+ }
libvlc_media_list_t * p_subitems = libvlc_media_subitems( p_md );
libvlc_media_release( p_md );
@@ -167,6 +172,9 @@ libvlc_media_list_item_at_path( libvlc_media_list_t * p_mlist, const libvlc_medi
{
libvlc_media_t* p_md = libvlc_media_list_item_at_index( p_current_mlist, path[i] );
+ if( !p_md )
+ return NULL;
+
if( p_current_mlist != p_mlist )
libvlc_media_list_release( p_current_mlist );
@@ -208,6 +216,9 @@ libvlc_media_list_parentlist_at_path( libvlc_media_list_t * p_mlist, const libvl
libvlc_media_t* p_md = libvlc_media_list_item_at_index( p_current_mlist, path[i] );
+ if( !p_md )
+ return NULL;
+
p_current_mlist = libvlc_media_subitems( p_md );
libvlc_media_release( p_md );
=====================================
lib/media_list_player.c
=====================================
@@ -171,7 +171,11 @@ get_next_path(libvlc_media_list_player_t * p_mlp, bool b_loop)
int depth = libvlc_media_list_path_depth(p_mlp->current_playing_item_path);
if (depth < 1 || !p_parent_of_playing_item)
+ {
+ if (p_parent_of_playing_item)
+ libvlc_media_list_release(p_parent_of_playing_item);
return NULL;
+ }
ret = libvlc_media_list_path_copy(p_mlp->current_playing_item_path);
ret[depth - 1]++; /* set to next element */
@@ -197,6 +201,7 @@ get_next_path(libvlc_media_list_player_t * p_mlp, bool b_loop)
}
ret[depth] = -1;
ret[depth-1]++;
+ libvlc_media_list_release(p_parent_of_playing_item);
p_parent_of_playing_item = libvlc_media_list_parentlist_at_path(
p_mlp->p_mlist,
ret);
@@ -436,7 +441,7 @@ uninstall_media_player_observer(libvlc_media_list_player_t * p_mlp)
*
* Playlist lock should be held
**************************************************************************/
-static void
+static int
set_current_playing_item(libvlc_media_list_player_t * p_mlp, libvlc_media_list_path_t path)
{
assert_locked(p_mlp);
@@ -449,12 +454,12 @@ set_current_playing_item(libvlc_media_list_player_t * p_mlp, libvlc_media_list_p
}
if (!path)
- return;
+ return -1;
libvlc_media_t * p_md;
p_md = libvlc_media_list_item_at_path(p_mlp->p_mlist, path);
if (!p_md)
- return;
+ return -1;
/* Make sure media_player_reached_end() won't get called */
uninstall_media_player_observer(p_mlp);
@@ -463,6 +468,8 @@ set_current_playing_item(libvlc_media_list_player_t * p_mlp, libvlc_media_list_p
install_media_player_observer(p_mlp);
libvlc_media_release(p_md); /* for libvlc_media_list_item_at_index */
+
+ return 0;
}
/*
@@ -690,8 +697,8 @@ int libvlc_media_list_player_play_item_at_index(libvlc_media_list_player_t * p_m
{
lock(p_mlp);
libvlc_media_list_path_t path = libvlc_media_list_path_with_root_index(i_index);
- set_current_playing_item(p_mlp, path);
libvlc_media_t *p_md = libvlc_media_player_get_media(p_mlp->p_mi);
+ int ret = set_current_playing_item(p_mlp, path);
libvlc_media_player_play(p_mlp->p_mi);
unlock(p_mlp);
@@ -704,7 +711,7 @@ int libvlc_media_list_player_play_item_at_index(libvlc_media_list_player_t * p_m
event.u.media_list_player_next_item_set.item = p_md;
libvlc_event_send(&p_mlp->event_manager, &event);
libvlc_media_release(p_md);
- return 0;
+ return ret;
}
/**************************************************************************
@@ -721,10 +728,10 @@ int libvlc_media_list_player_play_item(libvlc_media_list_player_t * p_mlp, libvl
return -1;
}
- set_current_playing_item(p_mlp, path);
+ int ret = set_current_playing_item(p_mlp, path);
libvlc_media_player_play(p_mlp->p_mi);
unlock(p_mlp);
- return 0;
+ return ret;
}
/**************************************************************************
@@ -783,6 +790,7 @@ static int set_relative_playlist_position_and_play(
libvlc_media_list_path_t path = p_mlp->current_playing_item_path;
+ int ret;
if(p_mlp->e_playback_mode != libvlc_playback_mode_repeat)
{
bool b_loop = (p_mlp->e_playback_mode == libvlc_playback_mode_loop);
@@ -790,20 +798,20 @@ static int set_relative_playlist_position_and_play(
while (i_relative_position > 0)
{
path = get_next_path(p_mlp, b_loop);
- set_current_playing_item(p_mlp, path);
+ ret = set_current_playing_item(p_mlp, path);
--i_relative_position;
}
while (i_relative_position < 0)
{
path = get_previous_path(p_mlp, b_loop);
- set_current_playing_item(p_mlp, path);
+ ret = set_current_playing_item(p_mlp, path);
++i_relative_position;
}
}
else
{
- set_current_playing_item(p_mlp, path);
+ ret = set_current_playing_item(p_mlp, path);
}
#ifdef DEBUG_MEDIA_LIST_PLAYER
@@ -811,7 +819,7 @@ static int set_relative_playlist_position_and_play(
libvlc_media_list_path_dump(path);
#endif
- if (!path)
+ if (!path || ret != 0)
{
libvlc_media_list_unlock(p_mlp->p_mlist);
/* Send list played event */
@@ -826,9 +834,12 @@ static int set_relative_playlist_position_and_play(
libvlc_media_list_unlock(p_mlp->p_mlist);
/* Send the next item event */
+ libvlc_media_t * p_md;
+ p_md = libvlc_media_list_item_at_path(p_mlp->p_mlist, path);
+ if (!p_md)
+ return -1;
libvlc_event_t event;
event.type = libvlc_MediaListPlayerNextItemSet;
- libvlc_media_t * p_md = libvlc_media_list_item_at_path(p_mlp->p_mlist, path);
event.u.media_list_player_next_item_set.item = p_md;
libvlc_event_send(&p_mlp->event_manager, &event);
libvlc_media_release(p_md);
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/f1ed769f555d083c876b5338ed41b64f57e0d48a...56529098b08432fb506e29cde42d987c2b355e03
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/f1ed769f555d083c876b5338ed41b64f57e0d48a...56529098b08432fb506e29cde42d987c2b355e03
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list