[MPlayer-dev-eng] [PATCH] Simplify frees in load_vob_subtitle.

Clément Bœsch ubitux at gmail.com
Sat Feb 5 22:12:00 CET 2011


Hi,

Small patch for the load_vob_subtitle function to cleanup a bit and
simplify the ways frees are handled. If you don't mind (maybe you find the
code no clearer after that or sth else), I'll commit this in 3 days.

Regards,

-- 
Clément B.
-------------- next part --------------
From aa164a22dac57106f3d0ec2f4874c341fe184319 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <ubitux at gmail.com>
Date: Mon, 24 Jan 2011 08:31:29 +0100
Subject: [PATCH] Simplify frees in load_vob_subtitle.

---
 sub/subreader.c |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/sub/subreader.c b/sub/subreader.c
index 216b094..97419a4 100644
--- a/sub/subreader.c
+++ b/sub/subreader.c
@@ -2144,7 +2144,7 @@ void load_subtitles(const char *fname, float fps, open_sub_func add_f)
 void load_vob_subtitle(const char *fname, const char * const ifo, void **spu,
                        open_vob_func add_f)
 {
-    char *name = NULL, *mp_subdir = NULL;
+    char *name = NULL, *mp_subdir = NULL, *psub = NULL;
 
     // Load subtitles specified by vobsub option
     if (vobsub_name) {
@@ -2171,7 +2171,7 @@ void load_vob_subtitle(const char *fname, const char * const ifo, void **spu,
         int i;
 
         for (i = 0; sub_paths[i]; i++) {
-            char *path, *psub;
+            char *path;
 
             path = mp_path_join(fname, sub_paths[i]);
             if (!path)
@@ -2182,25 +2182,24 @@ void load_vob_subtitle(const char *fname, const char * const ifo, void **spu,
             if (!psub)
                 goto out;
 
-            if (add_f(psub, ifo, 0, spu)) {
-                free(psub);
+            if (add_f(psub, ifo, 0, spu))
                 goto out;
-            }
             free(psub);
+            psub = NULL;
         }
     }
 
     // If still no VOB found, try loading it from ~/.mplayer/sub
     mp_subdir = get_path("sub/");
     if (mp_subdir) {
-        char *psub = mp_path_join(mp_subdir, mp_basename(name));
+        psub = mp_path_join(mp_subdir, mp_basename(name));
         add_f(psub, ifo, 0, spu);
-        free(psub);
     }
 
 out:
     free(mp_subdir);
     free(name);
+    free(psub);
 }
 
 void list_sub_file(sub_data* subd){
-- 
1.7.4

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20110205/4eae3c8e/attachment.pgp>


More information about the MPlayer-dev-eng mailing list