[libbluray-devel] Unify deallocators (nav_title_close(), nav_free_title_list()). Take pointer to pointer, set to NULL.
hpi1
git at videolan.org
Thu May 4 09:45:51 CEST 2017
libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Mon Apr 3 12:32:46 2017 +0300| [c39d238f5f64326ac89daba2d1e67d1a69f4ee00] | committer: hpi1
Unify deallocators (nav_title_close(), nav_free_title_list()). Take pointer to pointer, set to NULL.
> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=c39d238f5f64326ac89daba2d1e67d1a69f4ee00
---
src/libbluray/bdnav/navigation.c | 22 +++++++++++++++-------
src/libbluray/bdnav/navigation.h | 4 ++--
src/libbluray/bluray.c | 19 +++++--------------
3 files changed, 22 insertions(+), 23 deletions(-)
diff --git a/src/libbluray/bdnav/navigation.c b/src/libbluray/bdnav/navigation.c
index 93d07f53..12c4e70d 100644
--- a/src/libbluray/bdnav/navigation.c
+++ b/src/libbluray/bdnav/navigation.c
@@ -438,10 +438,12 @@ NAV_TITLE_LIST* nav_get_title_list(BD_DISC *disc, uint32_t flags, uint32_t min_t
return title_list;
}
-void nav_free_title_list(NAV_TITLE_LIST *title_list)
+void nav_free_title_list(NAV_TITLE_LIST **title_list)
{
- X_FREE(title_list->title_info);
- X_FREE(title_list);
+ if (*title_list) {
+ X_FREE((*title_list)->title_info);
+ X_FREE((*title_list));
+ }
}
/*
@@ -699,13 +701,11 @@ NAV_TITLE* nav_title_open(BD_DISC *disc, const char *playlist, unsigned angle)
return title;
}
-void nav_title_close(NAV_TITLE *title)
+static
+void _nav_title_close(NAV_TITLE *title)
{
unsigned ii, ss;
- if (!title)
- return;
-
if (title->sub_path) {
for (ss = 0; ss < title->sub_path_count; ss++) {
if (title->sub_path[ss].clip_list.clip) {
@@ -731,6 +731,14 @@ void nav_title_close(NAV_TITLE *title)
X_FREE(title);
}
+void nav_title_close(NAV_TITLE **title)
+{
+ if (*title) {
+ _nav_title_close(*title);
+ *title = NULL;
+ }
+}
+
// Search for random access point closest to the requested packet
// Packets are 192 byte TS packets
NAV_CLIP* nav_chapter_search(NAV_TITLE *title, unsigned chapter, uint32_t *clip_pkt, uint32_t *out_pkt)
diff --git a/src/libbluray/bdnav/navigation.h b/src/libbluray/bdnav/navigation.h
index 8f683dda..a07a9086 100644
--- a/src/libbluray/bdnav/navigation.h
+++ b/src/libbluray/bdnav/navigation.h
@@ -141,7 +141,7 @@ struct nav_title_list_s
BD_PRIVATE uint8_t nav_lookup_aspect(NAV_CLIP *clip, int pid);
BD_PRIVATE NAV_TITLE* nav_title_open(struct bd_disc *disc, const char *playlist, unsigned angle) BD_ATTR_MALLOC;
-BD_PRIVATE void nav_title_close(NAV_TITLE *title);
+BD_PRIVATE void nav_title_close(NAV_TITLE **title);
BD_PRIVATE NAV_CLIP* nav_next_clip(NAV_TITLE *title, NAV_CLIP *clip);
BD_PRIVATE NAV_CLIP* nav_packet_search(NAV_TITLE *title, uint32_t pkt, uint32_t *clip_pkt,
uint32_t *out_pkt, uint32_t *out_time);
@@ -155,6 +155,6 @@ BD_PRIVATE uint32_t nav_angle_change_search(NAV_CLIP *clip, uint32_t pkt, uint32
BD_PRIVATE NAV_CLIP* nav_set_angle(NAV_TITLE *title, NAV_CLIP *clip, unsigned angle);
BD_PRIVATE NAV_TITLE_LIST* nav_get_title_list(struct bd_disc *disc, uint32_t flags, uint32_t min_title_length) BD_ATTR_MALLOC;
-BD_PRIVATE void nav_free_title_list(NAV_TITLE_LIST *title_list);
+BD_PRIVATE void nav_free_title_list(NAV_TITLE_LIST **title_list);
#endif // _NAVIGATION_H_
diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index de641c93..835c6703 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -1501,12 +1501,8 @@ void bd_close(BLURAY *bd)
_close_preload(&bd->st_ig);
_close_preload(&bd->st_textst);
- if (bd->title_list != NULL) {
- nav_free_title_list(bd->title_list);
- }
- if (bd->title != NULL) {
- nav_title_close(bd->title);
- }
+ nav_free_title_list(&bd->title_list);
+ nav_title_close(&bd->title);
hdmv_vm_free(&bd->hdmv_vm);
@@ -2290,10 +2286,7 @@ static void _close_playlist(BLURAY *bd)
_close_preload(&bd->st_ig);
_close_preload(&bd->st_textst);
- if (bd->title) {
- nav_title_close(bd->title);
- bd->title = NULL;
- }
+ nav_title_close(&bd->title);
/* reset UO mask */
memset(&bd->st0.uo_mask, 0, sizeof(BD_UO_MASK));
@@ -2545,9 +2538,7 @@ uint32_t bd_get_titles(BLURAY *bd, uint8_t flags, uint32_t min_title_length)
return 0;
}
- if (bd->title_list != NULL) {
- nav_free_title_list(bd->title_list);
- }
+ nav_free_title_list(&bd->title_list);
bd->title_list = nav_get_title_list(bd->disc, flags, min_title_length);
if (!bd->title_list) {
@@ -2707,7 +2698,7 @@ static BLURAY_TITLE_INFO *_get_title_info(BLURAY *bd, uint32_t title_idx, uint32
title_info = _fill_title_info(title, title_idx, playlist);
- nav_title_close(title);
+ nav_title_close(&title);
return title_info;
}
More information about the libbluray-devel
mailing list