[libbluray-devel] commit: indx_free(), mobj_free(), hdmv_vm_free(): changed argument to **. Set original pointer to NULL. (hpi1 )

git at videolan.org git at videolan.org
Tue Oct 5 14:50:20 CEST 2010


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Tue Oct  5 15:46:11 2010 +0300| [65c6adaa959e1444e39e939d36e0f1c77c0cb267] | committer: hpi1 

indx_free(), mobj_free(), hdmv_vm_free(): changed argument to **. Set original pointer to NULL.

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

 src/examples/index_dump.c         |    2 +-
 src/examples/mobj_dump.c          |    2 +-
 src/libbluray/bdnav/index_parse.c |    8 ++++----
 src/libbluray/bdnav/index_parse.h |    2 +-
 src/libbluray/bluray.c            |    8 +++-----
 src/libbluray/hdmv/hdmv_vm.c      |   17 ++++++++++-------
 src/libbluray/hdmv/hdmv_vm.h      |    2 +-
 src/libbluray/hdmv/mobj_parse.c   |   12 ++++++------
 src/libbluray/hdmv/mobj_parse.h   |    2 +-
 9 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/src/examples/index_dump.c b/src/examples/index_dump.c
index a083aeb..aaa5da7 100644
--- a/src/examples/index_dump.c
+++ b/src/examples/index_dump.c
@@ -119,7 +119,7 @@ int main(int argc, const char *argv[])
     if (index) {
         _indx_print(index);
 
-        indx_free(index);
+        indx_free(&index);
     }
 
     return 0;
diff --git a/src/examples/mobj_dump.c b/src/examples/mobj_dump.c
index 79c1a80..f61a96a 100644
--- a/src/examples/mobj_dump.c
+++ b/src/examples/mobj_dump.c
@@ -76,7 +76,7 @@ int main(int argc, const char *argv[])
     if (mobj) {
         _mobj_print(mobj, disasm);
 
-        mobj_free(mobj);
+        mobj_free(&mobj);
     }
 
     return 0;
diff --git a/src/libbluray/bdnav/index_parse.c b/src/libbluray/bdnav/index_parse.c
index 9b33bc8..d1b05df 100644
--- a/src/libbluray/bdnav/index_parse.c
+++ b/src/libbluray/bdnav/index_parse.c
@@ -188,10 +188,10 @@ INDX_ROOT *indx_parse(const char *file_name)
     return NULL;
 }
 
-void indx_free(INDX_ROOT *index)
+void indx_free(INDX_ROOT **p)
 {
-    if (index) {
-        X_FREE(index->titles);
-        X_FREE(index);
+    if (p && *p) {
+        X_FREE((*p)->titles);
+        X_FREE(*p);
     }
 }
diff --git a/src/libbluray/bdnav/index_parse.h b/src/libbluray/bdnav/index_parse.h
index f7c6385..9a49477 100644
--- a/src/libbluray/bdnav/index_parse.h
+++ b/src/libbluray/bdnav/index_parse.h
@@ -107,7 +107,7 @@ typedef struct indx_root_s {
 
 
 BD_PRIVATE INDX_ROOT* indx_parse(const char *path); /* parse index.bdmv */
-BD_PRIVATE void       indx_free(INDX_ROOT *index);
+BD_PRIVATE void       indx_free(INDX_ROOT **index);
 
 #endif // _INDX_PARSE_H_
 
diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index c0f364f..67ae5be 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -519,10 +519,9 @@ void bd_close(BLURAY *bd)
         nav_title_close(bd->title);
     }
 
-    if (bd->hdmv_vm)
-        hdmv_vm_free(bd->hdmv_vm);
+    hdmv_vm_free(&bd->hdmv_vm);
 
-    indx_free(bd->index);
+    indx_free(&bd->index);
     bd_registers_free(bd->regs);
 
     X_FREE(bd->event_queue);
@@ -1361,8 +1360,7 @@ int bd_play(BLURAY *bd)
     bd->title_type = title_undef;
 
     if (bd->hdmv_vm) {
-        hdmv_vm_free(bd->hdmv_vm);
-        bd->hdmv_vm = NULL;
+        hdmv_vm_free(&bd->hdmv_vm);
         bd->hdmv_suspended = 1;
     }
 
diff --git a/src/libbluray/hdmv/hdmv_vm.c b/src/libbluray/hdmv/hdmv_vm.c
index 87106e3..a61c6b2 100644
--- a/src/libbluray/hdmv/hdmv_vm.c
+++ b/src/libbluray/hdmv/hdmv_vm.c
@@ -246,16 +246,19 @@ HDMV_VM *hdmv_vm_init(const char *disc_root, BD_REGISTERS *regs)
     return  p;
 }
 
-void hdmv_vm_free(HDMV_VM *p)
+void hdmv_vm_free(HDMV_VM **p)
 {
-    mobj_free(p->movie_objects);
+    if (p && *p) {
 
-    if (p->ig_object) {
-        X_FREE(p->ig_object->cmds);
-        X_FREE(p->ig_object);
-    }
+      mobj_free(&(*p)->movie_objects);
 
-    X_FREE(p);
+        if ((*p)->ig_object) {
+            X_FREE((*p)->ig_object->cmds);
+            X_FREE((*p)->ig_object);
+        }
+
+        X_FREE(*p);
+    }
 }
 
 /*
diff --git a/src/libbluray/hdmv/hdmv_vm.h b/src/libbluray/hdmv/hdmv_vm.h
index 97d5da4..16b6942 100644
--- a/src/libbluray/hdmv/hdmv_vm.h
+++ b/src/libbluray/hdmv/hdmv_vm.h
@@ -65,7 +65,7 @@ struct bd_registers_s;
 typedef struct hdmv_vm_s HDMV_VM;
 
 BD_PRIVATE HDMV_VM *hdmv_vm_init(const char *disc_root, struct bd_registers_s *regs);
-BD_PRIVATE void     hdmv_vm_free(HDMV_VM *p);
+BD_PRIVATE void     hdmv_vm_free(HDMV_VM **p);
 
 BD_PRIVATE int      hdmv_vm_select_object(HDMV_VM *p, int object);
 BD_PRIVATE int      hdmv_vm_set_object(HDMV_VM *p, int num_nav_cmds, void *nav_cmds);
diff --git a/src/libbluray/hdmv/mobj_parse.c b/src/libbluray/hdmv/mobj_parse.c
index 05105c1..5a42ff4 100644
--- a/src/libbluray/hdmv/mobj_parse.c
+++ b/src/libbluray/hdmv/mobj_parse.c
@@ -96,16 +96,16 @@ static int _mobj_parse_object(BITSTREAM *bs, MOBJ_OBJECT *obj)
     return 1;
 }
 
-void mobj_free(MOBJ_OBJECTS *objects)
+void mobj_free(MOBJ_OBJECTS **p)
 {
-    if (objects) {
+    if (p && *p) {
 
         int i;
-        for (i = 0 ; i < objects->num_objects; i++) {
-            X_FREE(objects->objects[i].cmds);
+        for (i = 0 ; i < (*p)->num_objects; i++) {
+            X_FREE((*p)->objects[i].cmds);
         }
 
-        X_FREE(objects);
+        X_FREE(*p);
     }
 }
 
@@ -152,7 +152,7 @@ MOBJ_OBJECTS *mobj_parse(const char *file_name)
     return objects;
 
  error:
-    mobj_free(objects);
+    mobj_free(&objects);
     file_close(fp);
     return NULL;
 }
diff --git a/src/libbluray/hdmv/mobj_parse.h b/src/libbluray/hdmv/mobj_parse.h
index 2bcc256..1ab43f1 100644
--- a/src/libbluray/hdmv/mobj_parse.h
+++ b/src/libbluray/hdmv/mobj_parse.h
@@ -64,7 +64,7 @@ typedef struct {
 
 BD_PRIVATE MOBJ_OBJECTS* mobj_parse(const char *path) BD_ATTR_MALLOC; /* parse MovieObject.bdmv */
 BD_PRIVATE void          mobj_parse_cmd(uint8_t *buf, MOBJ_CMD *cmd);
-BD_PRIVATE void          mobj_free(MOBJ_OBJECTS *index);
+BD_PRIVATE void          mobj_free(MOBJ_OBJECTS **index);
 
 BD_PRIVATE int mobj_sprint_cmd(char *buf, MOBJ_CMD *cmd); /* print MOBJ_CMD to string. buf is expected to be 256 bytes. */
 



More information about the libbluray-devel mailing list