[MPlayer-cvslog] r24879 - in trunk: libass/ass.c subreader.c subreader.h
iive
subversion at mplayerhq.hu
Sun Oct 28 15:26:05 CET 2007
Author: iive
Date: Sun Oct 28 15:26:05 2007
New Revision: 24879
Log:
Our enca code uses strdup() on the input encoding name, as we don't modify it we can use the original constant string.
Uses less memory, code is simpler and faster.
Fixes memory leak (noticed by ulion).
Modified:
trunk/libass/ass.c
trunk/subreader.c
trunk/subreader.h
Modified: trunk/libass/ass.c
==============================================================================
--- trunk/libass/ass.c (original)
+++ trunk/libass/ass.c Sun Oct 28 15:26:05 2007
@@ -804,7 +804,7 @@ static char* sub_recode(char* data, size
assert(codepage);
{
- char* cp_tmp = codepage ? strdup(codepage) : 0;
+ const char* cp_tmp = codepage;
#ifdef HAVE_ENCA
char enca_lang[3], enca_fallback[100];
if (sscanf(codepage, "enca:%2s:%99s", enca_lang, enca_fallback) == 2
@@ -816,9 +816,6 @@ static char* sub_recode(char* data, size
mp_msg(MSGT_ASS,MSGL_V,"LIBSUB: opened iconv descriptor.\n");
} else
mp_msg(MSGT_ASS,MSGL_ERR,MSGTR_LIBASS_ErrorOpeningIconvDescriptor);
-#ifdef HAVE_ENCA
- if (cp_tmp) free(cp_tmp);
-#endif
}
{
Modified: trunk/subreader.c
==============================================================================
--- trunk/subreader.c (original)
+++ trunk/subreader.c Sun Oct 28 15:26:05 2007
@@ -1083,15 +1083,13 @@ void subcp_open (stream_t *st)
char *tocp = "UTF-8";
if (sub_cp){
- char *cp_tmp = sub_cp;
+ const char *cp_tmp = sub_cp;
#ifdef HAVE_ENCA
char enca_lang[3], enca_fallback[100];
- int free_cp_tmp = 0;
if (sscanf(sub_cp, "enca:%2s:%99s", enca_lang, enca_fallback) == 2
|| sscanf(sub_cp, "ENCA:%2s:%99s", enca_lang, enca_fallback) == 2) {
if (st && st->flags & STREAM_SEEK ) {
cp_tmp = guess_cp(st, enca_lang, enca_fallback);
- free_cp_tmp = 1;
} else {
cp_tmp = enca_fallback;
if (st)
@@ -1104,9 +1102,6 @@ void subcp_open (stream_t *st)
sub_utf8 = 2;
} else
mp_msg(MSGT_SUBREADER,MSGL_ERR,"SUB: error opening iconv descriptor.\n");
-#ifdef HAVE_ENCA
- if (free_cp_tmp && cp_tmp) free(cp_tmp);
-#endif
}
}
@@ -1275,13 +1270,13 @@ struct subreader {
};
#ifdef HAVE_ENCA
-void* guess_buffer_cp(unsigned char* buffer, int buflen, char *preferred_language, char *fallback)
+const char* guess_buffer_cp(unsigned char* buffer, int buflen, char *preferred_language, const char *fallback)
{
const char **languages;
size_t langcnt;
EncaAnalyser analyser;
EncaEncoding encoding;
- char *detected_sub_cp = NULL;
+ const char *detected_sub_cp = NULL;
int i;
languages = enca_get_languages(&langcnt);
@@ -1299,7 +1294,7 @@ void* guess_buffer_cp(unsigned char* buf
encoding = enca_analyse_const(analyser, buffer, buflen);
tmp = enca_charset_name(encoding.charset, ENCA_NAME_STYLE_ICONV);
if (tmp && encoding.charset != ENCA_CS_UNKNOWN) {
- detected_sub_cp = strdup(tmp);
+ detected_sub_cp = tmp;
mp_msg(MSGT_SUBREADER, MSGL_INFO, "ENCA detected charset: %s\n", tmp);
}
enca_analyser_free(analyser);
@@ -1308,7 +1303,7 @@ void* guess_buffer_cp(unsigned char* buf
free(languages);
if (!detected_sub_cp) {
- detected_sub_cp = strdup(fallback);
+ detected_sub_cp = fallback;
mp_msg(MSGT_SUBREADER, MSGL_INFO, "ENCA detection failed: fallback to %s\n", fallback);
}
@@ -1316,11 +1311,11 @@ void* guess_buffer_cp(unsigned char* buf
}
#define MAX_GUESS_BUFFER_SIZE (256*1024)
-void* guess_cp(stream_t *st, char *preferred_language, char *fallback)
+const char* guess_cp(stream_t *st, char *preferred_language, const char *fallback)
{
size_t buflen;
unsigned char *buffer;
- char *detected_sub_cp = NULL;
+ const char *detected_sub_cp = NULL;
buffer = malloc(MAX_GUESS_BUFFER_SIZE);
buflen = stream_read(st,buffer, MAX_GUESS_BUFFER_SIZE);
Modified: trunk/subreader.h
==============================================================================
--- trunk/subreader.h (original)
+++ trunk/subreader.h Sun Oct 28 15:26:05 2007
@@ -74,8 +74,8 @@ struct stream_st;
void subcp_open (struct stream_st *st); /* for demux_ogg.c */
void subcp_close (void); /* for demux_ogg.c */
#ifdef HAVE_ENCA
-void* guess_buffer_cp(unsigned char* buffer, int buflen, char *preferred_language, char *fallback);
-void* guess_cp(struct stream_st *st, char *preferred_language, char *fallback);
+const char* guess_buffer_cp(unsigned char* buffer, int buflen, char *preferred_language, const char *fallback);
+const char* guess_cp(struct stream_st *st, char *preferred_language, const char *fallback);
#endif
char ** sub_filenames(const char *path, char *fname);
void list_sub_file(sub_data* subd);
More information about the MPlayer-cvslog
mailing list