[x265] [PATCH] cli: fix crash when pass the unrecognized options

gopu at multicorewareinc.com gopu at multicorewareinc.com
Wed May 20 08:53:09 CEST 2015


# HG changeset patch
# User Gopu Govindaswamy <gopu at multicorewareinc.com>
# Date 1432104767 -19800
#      Wed May 20 12:22:47 2015 +0530
# Node ID 86c12f594b8964909f311a5a39f3941f73c94523
# Parent  9b31a8a7bd57efededcc3884ee7777c09f649394
cli: fix crash when pass the unrecognized options

diff -r 9b31a8a7bd57 -r 86c12f594b89 source/x265.cpp
--- a/source/x265.cpp	Tue May 19 19:51:56 2015 -0500
+++ b/source/x265.cpp	Wed May 20 12:22:47 2015 +0530
@@ -176,6 +176,20 @@
         return true;
     }
 
+    api = x265_api_get(outputBitDepth);
+    if (!api)
+    {
+        x265_log(NULL, X265_LOG_WARNING, "falling back to default bit-depth\n");
+        api = x265_api_get(0);
+    }
+
+    param = api->param_alloc();
+    if (!param)
+    {
+        x265_log(NULL, X265_LOG_ERROR, "param alloc failed\n");
+        return true;
+    }
+
     /* Presets are applied before all other options. */
     for (optind = 0;; )
     {
@@ -189,21 +203,11 @@
         else if (c == 'D')
             outputBitDepth = atoi(optarg);
         else if (c == '?')
+        {
             showHelp(param);
-    }
-
-    api = x265_api_get(outputBitDepth);
-    if (!api)
-    {
-        x265_log(NULL, X265_LOG_WARNING, "falling back to default bit-depth\n");
-        api = x265_api_get(0);
-    }
-
-    param = api->param_alloc();
-    if (!param)
-    {
-        x265_log(NULL, X265_LOG_ERROR, "param alloc failed\n");
-        return true;
+            api->param_free(param);
+            exit(1);
+        }
     }
 
     if (api->param_default_preset(param, preset, tune) < 0)
@@ -223,7 +227,8 @@
         {
         case 'h':
             showHelp(param);
-            break;
+            api->param_free(param);
+            exit(1);
 
         case 'V':
             printVersion(param);
@@ -310,7 +315,11 @@
     }
 
     if (argc <= 1 || help)
+    {
         showHelp(param);
+        api->param_free(param);
+        exit(1);
+    }
 
     if (inputfn == NULL || outputfn == NULL)
     {
diff -r 9b31a8a7bd57 -r 86c12f594b89 source/x265cli.h
--- a/source/x265cli.h	Tue May 19 19:51:56 2015 -0500
+++ b/source/x265cli.h	Wed May 20 12:22:47 2015 +0530
@@ -422,7 +422,6 @@
     if (level < X265_LOG_DEBUG)
         printf("\nUse --log-level full --help for a full listing\n");
     printf("\n\nComplete documentation may be found at http://x265.readthedocs.org/en/default/cli.html\n");
-    exit(1);
 }
 
 #ifdef __cplusplus


More information about the x265-devel mailing list