[libbluray-devel] Set pointer to NULL in clpi_free() and mpls_free()

hpi1 git at videolan.org
Thu May 4 09:39:48 CEST 2017


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Mon Apr  3 11:11:18 2017 +0300| [0952ec18c7f0f74a54ac6d9dfc374546d3c706d5] | committer: hpi1

Set pointer to NULL in clpi_free() and mpls_free()

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=0952ec18c7f0f74a54ac6d9dfc374546d3c706d5
---

 src/libbluray/bdnav/clpi_parse.c | 29 +++++++++++++++++------------
 src/libbluray/bdnav/clpi_parse.h |  2 +-
 src/libbluray/bdnav/mpls_parse.c | 10 +++++-----
 src/libbluray/bdnav/mpls_parse.h |  2 +-
 src/libbluray/bdnav/navigation.c | 17 ++++++++---------
 src/libbluray/bluray.c           |  4 ++--
 6 files changed, 34 insertions(+), 30 deletions(-)

diff --git a/src/libbluray/bdnav/clpi_parse.c b/src/libbluray/bdnav/clpi_parse.c
index 34c1dec3..839e10c3 100644
--- a/src/libbluray/bdnav/clpi_parse.c
+++ b/src/libbluray/bdnav/clpi_parse.c
@@ -707,15 +707,11 @@ _clean_cpi(CLPI_CPI *cpi)
     }
 }
 
-void
-clpi_free(CLPI_CL *cl)
+static void
+_clpi_free(CLPI_CL *cl)
 {
     int ii;
 
-    if (cl == NULL) {
-        return;
-    }
-
     X_FREE(cl->clip.atc_delta);
     X_FREE(cl->clip.font_info.font);
 
@@ -738,6 +734,15 @@ clpi_free(CLPI_CL *cl)
     X_FREE(cl);
 }
 
+void
+clpi_free(CLPI_CL **cl)
+{
+    if (*cl) {
+        _clpi_free(*cl);
+        *cl = NULL;
+    }
+}
+
 static CLPI_CL*
 _clpi_parse(BD_FILE_H *fp)
 {
@@ -756,7 +761,7 @@ _clpi_parse(BD_FILE_H *fp)
     }
 
     if (!_parse_header(&bits, cl)) {
-        clpi_free(cl);
+        _clpi_free(cl);
         return NULL;
     }
 
@@ -768,19 +773,19 @@ _clpi_parse(BD_FILE_H *fp)
     }
 
     if (!_parse_clipinfo(&bits, cl)) {
-        clpi_free(cl);
+        _clpi_free(cl);
         return NULL;
     }
     if (!_parse_sequence(&bits, cl)) {
-        clpi_free(cl);
+        _clpi_free(cl);
         return NULL;
     }
     if (!_parse_program_info(&bits, cl)) {
-        clpi_free(cl);
+        _clpi_free(cl);
         return NULL;
     }
     if (!_parse_cpi_info(&bits, cl)) {
-        clpi_free(cl);
+        _clpi_free(cl);
         return NULL;
     }
 
@@ -957,6 +962,6 @@ clpi_copy(const CLPI_CL* src_cl)
 
  fail:
     BD_DEBUG(DBG_CRIT, "out of memory\n");
-    clpi_free(dest_cl);
+    clpi_free(&dest_cl);
     return NULL;
 }
diff --git a/src/libbluray/bdnav/clpi_parse.h b/src/libbluray/bdnav/clpi_parse.h
index 2263f66c..987da657 100644
--- a/src/libbluray/bdnav/clpi_parse.h
+++ b/src/libbluray/bdnav/clpi_parse.h
@@ -33,6 +33,6 @@ BD_PRIVATE uint32_t clpi_access_point(const CLPI_CL *cl, uint32_t pkt, int next,
 BD_PRIVATE CLPI_CL* clpi_parse(const char *path) BD_ATTR_MALLOC;
 BD_PRIVATE CLPI_CL* clpi_get(struct bd_disc *disc, const char *file);
 BD_PRIVATE CLPI_CL* clpi_copy(const CLPI_CL* src_cl);
-BD_PRIVATE void clpi_free(CLPI_CL *cl);
+BD_PRIVATE void clpi_free(CLPI_CL **cl);
 
 #endif // _CLPI_PARSE_H_
diff --git a/src/libbluray/bdnav/mpls_parse.c b/src/libbluray/bdnav/mpls_parse.c
index 53522224..b003d11c 100644
--- a/src/libbluray/bdnav/mpls_parse.c
+++ b/src/libbluray/bdnav/mpls_parse.c
@@ -770,9 +770,6 @@ _clean_playlist(MPLS_PL *pl)
 {
     int ii;
 
-    if (pl == NULL) {
-        return;
-    }
     if (pl->play_item != NULL) {
         for (ii = 0; ii < pl->list_count; ii++) {
             _clean_playitem(&pl->play_item[ii]);
@@ -803,9 +800,12 @@ _clean_playlist(MPLS_PL *pl)
 }
 
 void
-mpls_free(MPLS_PL *pl)
+mpls_free(MPLS_PL **pl)
 {
-    _clean_playlist(pl);
+    if (*pl) {
+        _clean_playlist(*pl);
+        *pl = NULL;
+    }
 }
 
 static int
diff --git a/src/libbluray/bdnav/mpls_parse.h b/src/libbluray/bdnav/mpls_parse.h
index e0e57a00..1ef0a070 100644
--- a/src/libbluray/bdnav/mpls_parse.h
+++ b/src/libbluray/bdnav/mpls_parse.h
@@ -194,7 +194,7 @@ struct bd_disc;
 
 BD_PRIVATE MPLS_PL* mpls_parse(const char *path) BD_ATTR_MALLOC;
 BD_PRIVATE MPLS_PL* mpls_get(struct bd_disc *disc, const char *file);
-BD_PRIVATE void mpls_free(MPLS_PL *pl);
+BD_PRIVATE void mpls_free(MPLS_PL **pl);
 
 BD_PRIVATE int  mpls_parse_uo(uint8_t *buf, BD_UO_MASK *uo);
 
diff --git a/src/libbluray/bdnav/navigation.c b/src/libbluray/bdnav/navigation.c
index 77ed1fbe..93d07f53 100644
--- a/src/libbluray/bdnav/navigation.c
+++ b/src/libbluray/bdnav/navigation.c
@@ -386,16 +386,16 @@ NAV_TITLE_LIST* nav_get_title_list(BD_DISC *disc, uint32_t flags, uint32_t min_t
         if (pl != NULL) {
             if ((flags & TITLES_FILTER_DUP_TITLE) &&
                 !_filter_dup(pl_list, ii, pl)) {
-                mpls_free(pl);
+                mpls_free(&pl);
                 continue;
             }
             if ((flags & TITLES_FILTER_DUP_CLIP) && !_filter_repeats(pl, 2)) {
-                mpls_free(pl);
+                mpls_free(&pl);
                 continue;
             }
             if (min_title_length > 0 &&
                 _pl_duration(pl) < min_title_length*45000) {
-                mpls_free(pl);
+                mpls_free(&pl);
                 continue;
             }
             if (ii >= title_info_alloc) {
@@ -432,7 +432,7 @@ NAV_TITLE_LIST* nav_get_title_list(BD_DISC *disc, uint32_t flags, uint32_t min_t
 
     title_list->count = ii;
     for (ii = 0; ii < title_list->count; ii++) {
-        mpls_free(pl_list[ii]);
+        mpls_free(&pl_list[ii]);
     }
     X_FREE(pl_list);
     return title_list;
@@ -581,8 +581,7 @@ static void _fill_clip(NAV_TITLE *title,
     strncpy(&clip->name[5], ".m2ts", 6);
     clip->clip_id = atoi(mpls_clip[clip->angle].clip_id);
 
-    clpi_free(clip->cl);
-    clip->cl = NULL;
+    clpi_free(&clip->cl);
 
     file = str_printf("%s.clpi", mpls_clip[clip->angle].clip_id);
     if (file) {
@@ -711,7 +710,7 @@ void nav_title_close(NAV_TITLE *title)
         for (ss = 0; ss < title->sub_path_count; ss++) {
             if (title->sub_path[ss].clip_list.clip) {
                 for (ii = 0; ii < title->sub_path[ss].clip_list.count; ii++) {
-                    clpi_free(title->sub_path[ss].clip_list.clip[ii].cl);
+                    clpi_free(&title->sub_path[ss].clip_list.clip[ii].cl);
                 }
                 X_FREE(title->sub_path[ss].clip_list.clip);
             }
@@ -721,12 +720,12 @@ void nav_title_close(NAV_TITLE *title)
 
     if (title->clip_list.clip) {
         for (ii = 0; ii < title->clip_list.count; ii++) {
-            clpi_free(title->clip_list.clip[ii].cl);
+            clpi_free(&title->clip_list.clip[ii].cl);
         }
         X_FREE(title->clip_list.clip);
     }
 
-    mpls_free(title->pl);
+    mpls_free(&title->pl);
     X_FREE(title->chap_list.mark);
     X_FREE(title->mark_list.mark);
     X_FREE(title);
diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index 4eddac0f..de641c93 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -3821,7 +3821,7 @@ struct clpi_cl *bd_read_clpi(const char *path)
 
 void bd_free_clpi(struct clpi_cl *cl)
 {
-    clpi_free(cl);
+    clpi_free(&cl);
 }
 
 struct mpls_pl *bd_read_mpls(const char *mpls_file)
@@ -3831,7 +3831,7 @@ struct mpls_pl *bd_read_mpls(const char *mpls_file)
 
 void bd_free_mpls(struct mpls_pl *pl)
 {
-    mpls_free(pl);
+    mpls_free(&pl);
 }
 
 struct mobj_objects *bd_read_mobj(const char *mobj_file)



More information about the libbluray-devel mailing list