[libbluray-devel] commit: Make free functions accept NULL pointer (free() semantics) (hpi1 )

git at videolan.org git at videolan.org
Tue Aug 17 01:53:56 CEST 2010


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Mon Aug  9 16:56:55 2010 +0300| [91d00575a03474ca3623035f9bdd87c5884b23db] | committer: hpi1 

Make free functions accept NULL pointer (free() semantics)

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

 src/libbluray/bdj/bdj.c          |   16 +++++++++-------
 src/libbluray/bdnav/navigation.c |   38 +++++++++++++++++++++-----------------
 src/libbluray/hdmv/hdmv_vm.c     |    6 ++++--
 3 files changed, 34 insertions(+), 26 deletions(-)

diff --git a/src/libbluray/bdj/bdj.c b/src/libbluray/bdj/bdj.c
index bfa9ae9..29dfbf6 100644
--- a/src/libbluray/bdj/bdj.c
+++ b/src/libbluray/bdj/bdj.c
@@ -113,17 +113,19 @@ BDJAVA* bdj_open(const char *path, const char* start, void* bd, void* registers)
 
 void bdj_close(BDJAVA *bdjava)
 {
-    JNIEnv* env = bdjava->env;
-    JavaVM* jvm = bdjava->jvm;
+    if (bdjava) {
+        JNIEnv* env = bdjava->env;
+        JavaVM* jvm = bdjava->jvm;
 
-    jclass init_class = (*env)->FindClass(env, "org/videolan/BDJLoader");
-    jmethodID shutdown_id = (*env)->GetStaticMethodID(env, init_class,
+        jclass init_class = (*env)->FindClass(env, "org/videolan/BDJLoader");
+        jmethodID shutdown_id = (*env)->GetStaticMethodID(env, init_class,
             "Shutdown", "()V");
-    (*env)->CallStaticVoidMethod(env, init_class, shutdown_id);
+        (*env)->CallStaticVoidMethod(env, init_class, shutdown_id);
 
-    (*jvm)->DestroyJavaVM(jvm);
+        (*jvm)->DestroyJavaVM(jvm);
 
-    free(bdjava);
+        free(bdjava);
+    }
 }
 
 void bdj_send_event(BDJAVA *bdjava, int type, int keyCode)
diff --git a/src/libbluray/bdnav/navigation.c b/src/libbluray/bdnav/navigation.c
index adca357..af987b0 100644
--- a/src/libbluray/bdnav/navigation.c
+++ b/src/libbluray/bdnav/navigation.c
@@ -198,8 +198,10 @@ NAV_TITLE_LIST* nav_get_title_list(const char *root, uint32_t flags)
 
 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);
+    }
 }
 
 char* nav_find_main_title(const char *root)
@@ -490,25 +492,27 @@ NAV_TITLE* nav_title_open(const char *root, const char *playlist)
 
 void nav_title_close(NAV_TITLE *title)
 {
-    unsigned ii, ss;
+    if (title) {
+        unsigned ii, ss;
 
-    for (ss = 0; ss < title->sub_path_count; ss++) {
-        for (ii = 0; ii < title->sub_path[ss].clip_list.count; ii++) {
-            clpi_free(title->sub_path[ss].clip_list.clip[ii].cl);
+        for (ss = 0; ss < title->sub_path_count; ss++) {
+            for (ii = 0; ii < title->sub_path[ss].clip_list.count; ii++) {
+                clpi_free(title->sub_path[ss].clip_list.clip[ii].cl);
+            }
+            X_FREE(title->sub_path[ss].clip_list.clip);
         }
-        X_FREE(title->sub_path[ss].clip_list.clip);
-    }
-    X_FREE(title->sub_path);
+        X_FREE(title->sub_path);
 
-    for (ii = 0; ii < title->pl->list_count; ii++) {
-        clpi_free(title->clip_list.clip[ii].cl);
-    }
-    mpls_free(title->pl);
-    X_FREE(title->clip_list.clip);
-    X_FREE(title->root);
-    X_FREE(title->chap_list.mark);
-    X_FREE(title->mark_list.mark);
-    X_FREE(title);
+        for (ii = 0; ii < title->pl->list_count; ii++) {
+            clpi_free(title->clip_list.clip[ii].cl);
+        }
+        mpls_free(title->pl);
+        X_FREE(title->clip_list.clip);
+        X_FREE(title->root);
+        X_FREE(title->chap_list.mark);
+        X_FREE(title->mark_list.mark);
+        X_FREE(title);
+    }
 }
 
 // Search for random access point closest to the requested packet
diff --git a/src/libbluray/hdmv/hdmv_vm.c b/src/libbluray/hdmv/hdmv_vm.c
index 3063de7..194e285 100644
--- a/src/libbluray/hdmv/hdmv_vm.c
+++ b/src/libbluray/hdmv/hdmv_vm.c
@@ -238,9 +238,11 @@ HDMV_VM *hdmv_vm_init(const char *disc_root, BD_REGISTERS *regs)
 
 void hdmv_vm_free(HDMV_VM *p)
 {
-    mobj_free(p->movie_objects);
+    if (p) {
+        mobj_free(p->movie_objects);
 
-    X_FREE(p);
+        X_FREE(p);
+    }
 }
 
 /*



More information about the libbluray-devel mailing list