summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2005-06-01 09:01:41 +0000
committerreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2005-06-01 09:01:41 +0000
commit46630a96a93494178f58f838337944313605966a (patch)
treefa70d7b94581bfaa4625dc67bc88d0518ce61003
parent0ff088813f7061d60f134874c0c3b8f170ebed4e (diff)
downloadmpv-46630a96a93494178f58f838337944313605966a.tar.bz2
mpv-46630a96a93494178f58f838337944313605966a.tar.xz
strdup subtitle filename at a more appropriate place, fixing memleaks and
double frees. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@15604 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r--Gui/interface.c2
-rw-r--r--mencoder.c13
-rw-r--r--mplayer.c10
-rw-r--r--subreader.c3
4 files changed, 18 insertions, 10 deletions
diff --git a/Gui/interface.c b/Gui/interface.c
index 7f8bfb10c2..555b02b850 100644
--- a/Gui/interface.c
+++ b/Gui/interface.c
@@ -486,7 +486,7 @@ void guiLoadSubtitle( char * name )
if ( name )
{
mp_msg( MSGT_GPLAYER,MSGL_INFO,MSGTR_LoadingSubtitles,name );
- subdata=sub_read_file( gstrdup( name ), guiIntfStruct.FPS );
+ subdata=sub_read_file( name, guiIntfStruct.FPS );
if ( !subdata ) mp_msg( MSGT_GPLAYER,MSGL_ERR,MSGTR_CantLoadSub,name );
sub_name = (malloc(2 * sizeof(char*))); //when mplayer will be restarted
sub_name[0] = strdup(name); //sub_name[0] will be read
diff --git a/mencoder.c b/mencoder.c
index 6714d49114..70470cccfc 100644
--- a/mencoder.c
+++ b/mencoder.c
@@ -591,8 +591,17 @@ if(sh_audio && (out_audio_codec || seek_to_sec || !sh_audio->wf || playback_spee
if(!subdata) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,sub_name[0]);
} else
if(sub_auto) { // auto load sub file ...
- subdata=sub_read_file( filename ? sub_filenames( get_path("sub/"), filename )[0]
- : "default.sub", sh_video->fps );
+ char **tmp = NULL;
+ int i = 0;
+ if (filename) {
+ char *psub = get_path( "sub/" );
+ tmp = sub_filenames((psub ? psub : ""), filename);
+ free(psub);
+ }
+ subdata=sub_read_file(tmp ? tmp[0] : "default.sub", sh_video->fps);
+ while (tmp && tmp[i])
+ free(tmp[i++]);
+ free(tmp);
}
#endif
diff --git a/mplayer.c b/mplayer.c
index 56d32cf63f..1ee07efc10 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -1914,18 +1914,18 @@ if(sh_video) {
if(sub_auto) { // auto load sub file ...
char *psub = get_path( "sub/" );
char **tmp = sub_filenames((psub ? psub : ""), filename);
- char **tmp2 = tmp;
+ int i = 0;
free(psub); // release the buffer created by get_path() above
- while (*tmp2)
- add_subtitles (*tmp2++, sh_video->fps, 0);
+ while (tmp[i]) {
+ add_subtitles (tmp[i], sh_video->fps, 0);
+ free(tmp[i++]);
+ }
free(tmp);
if (set_of_sub_size == 0)
{
add_subtitles (mem_ptr=get_path("default.sub"), sh_video->fps, 1);
free(mem_ptr); // release the buffer created by get_path()
}
- if (set_of_sub_size > 0)
- add_subtitles (NULL, sh_video->fps, 1);
}
if (set_of_sub_size > 0) {
// setup global sub numbering
diff --git a/subreader.c b/subreader.c
index 9d5486e3ee..e2cdb674dc 100644
--- a/subreader.c
+++ b/subreader.c
@@ -1350,7 +1350,6 @@ void* guess_cp(FILE *fd, char *preferred_language, char *fallback)
#endif
sub_data* sub_read_file (char *filename, float fps) {
- //filename is assumed to be malloc'ed, free() is used in sub_free()
FILE *fd;
int n_max, n_first, i, j, sub_first, sub_orig;
subtitle *first, *second, *sub, *return_sub;
@@ -1718,7 +1717,7 @@ if ((suboverlap_enabled == 2) ||
}
if (return_sub == NULL) return NULL;
subt_data = (sub_data *)malloc(sizeof(sub_data));
- subt_data->filename = filename;
+ subt_data->filename = strdup(filename);
subt_data->sub_uses_time = uses_time;
subt_data->sub_num = sub_num;
subt_data->sub_errs = sub_errs;