summaryrefslogtreecommitdiffstats
path: root/libvo
diff options
context:
space:
mode:
authorivo <ivo@b3059339-0415-0410-9bf9-f77b7e298cf2>2004-09-11 19:59:31 +0000
committerivo <ivo@b3059339-0415-0410-9bf9-f77b7e298cf2>2004-09-11 19:59:31 +0000
commita35c5903bb15d489f038c1dc0cd805eed43162be (patch)
tree399590f7c65d688428729aeb2a71b5aae0012367 /libvo
parent6c26b38c4c584a5235077614902024b720a38be3 (diff)
downloadmpv-a35c5903bb15d489f038c1dc0cd805eed43162be.tar.bz2
mpv-a35c5903bb15d489f038c1dc0cd805eed43162be.tar.xz
* Changed malloc and strncpy to strdup. Less code.
* More error checking. If malloc or strdup fails, print message and exit. * Free malloc'd memory when uninit is called. * Moved default of jpeg_outdir to preinit, so it is always malloc'd and can easily be freed at uninit. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@13317 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libvo')
-rw-r--r--libvo/vo_jpeg.c58
1 files changed, 38 insertions, 20 deletions
diff --git a/libvo/vo_jpeg.c b/libvo/vo_jpeg.c
index 1ece703020..01163667b1 100644
--- a/libvo/vo_jpeg.c
+++ b/libvo/vo_jpeg.c
@@ -72,7 +72,7 @@ int jpeg_progressive_mode = 0;
int jpeg_optimize = 100;
int jpeg_smooth = 0;
int jpeg_quality = 75;
-char *jpeg_outdir = ".";
+char *jpeg_outdir = NULL;
char *jpeg_subdirs = NULL;
int jpeg_maxfiles = 1000;
@@ -280,6 +280,14 @@ static uint32_t query_format(uint32_t format)
static void uninit(void)
{
+ if (jpeg_subdirs) {
+ free(jpeg_subdirs);
+ jpeg_subdirs = NULL;
+ }
+ if (jpeg_outdir) {
+ free(jpeg_outdir);
+ jpeg_outdir = NULL;
+ }
}
/* ------------------------------------------------------------------------- */
@@ -290,10 +298,25 @@ static void check_events(void)
/* ------------------------------------------------------------------------- */
+/** \brief Memory allocation failed.
+ *
+ * This function can be called if memory allocations failed. It prints a
+ * message and exits the player.
+ *
+ * \return none It never returns.
+ */
+
+void jpeg_malloc_failed(void) {
+ mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name,
+ MSGTR_MemAllocFailed);
+ exit_player(MSGTR_Exit_error);
+}
+
+/* ------------------------------------------------------------------------- */
+
static uint32_t preinit(const char *arg)
{
char *buf; /* buf is used to store parsed string values */
- int length; /* length is used when calculating the length of buf */
int value; /* storage for parsed integer values */
mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
@@ -403,18 +426,13 @@ static uint32_t preinit(const char *arg)
} else if (!strncmp(arg, "outdir=", 7)) {
arg += 7;
buf = malloc(strlen(arg)+1); /* maximum length possible */
- if (!buf) {
- mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name,
- MSGTR_MemAllocFailed);
- exit_player(MSGTR_Exit_error);
- }
+ if (!buf) jpeg_malloc_failed(); /* print msg and exit */
if (sscanf(arg, "%[^:]", buf) == 1) {
mp_msg(MSGT_VO, MSGL_INFO, "%s: %s --> %s\n",
info.short_name, "outdir", buf);
- length = strlen(buf);
- arg += length;
- jpeg_outdir = malloc(length+1);
- strncpy(jpeg_outdir, buf, length+1);
+ arg += strlen(buf);
+ jpeg_outdir = strdup(buf);
+ if (!jpeg_outdir) jpeg_malloc_failed();
free(buf);
} else {
mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n",
@@ -425,18 +443,13 @@ static uint32_t preinit(const char *arg)
} else if (!strncmp(arg, "subdirs=", 8)) {
arg += 8;
buf = malloc(strlen(arg)+1); /* maximum length possible */
- if (!buf) {
- mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name,
- MSGTR_MemAllocFailed);
- exit_player(MSGTR_Exit_error);
- }
+ if (!buf) jpeg_malloc_failed();
if (sscanf(arg, "%[^:]", buf) == 1) {
mp_msg(MSGT_VO, MSGL_INFO, "%s: %s --> %s\n",
info.short_name, "subdirs", buf);
- length = strlen(buf);
- arg += length;
- jpeg_subdirs = malloc(length+1);
- strncpy(jpeg_subdirs, buf, length+1);
+ arg += strlen(buf);
+ jpeg_subdirs = strdup(buf);
+ if (!jpeg_subdirs) jpeg_malloc_failed();
free(buf);
} else {
mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n",
@@ -477,6 +490,11 @@ static uint32_t preinit(const char *arg)
} /* end while */
} /* endif */
+ /* If jpeg_outdir is not set by an option, resort to default of "." */
+ if (!jpeg_outdir) {
+ jpeg_outdir = strdup(".");
+ }
+
mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
MSGTR_VO_SuboptionsParsedOK);
return 0;