Commit:    9a86784859067eaca44cad7f8b4aea00e3ffe6b2
Author:    Johannes Schlüter <johan...@php.net>         Wed, 27 Jun 2012 
11:46:57 +0200
Parents:   7a0f4cfddef2761b5893ececc4682e0cbd90facc 
bc0972e78daec4d7b7adccb7116f8ded2ca5044d
Branches:  PHP-5.4 master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=9a86784859067eaca44cad7f8b4aea00e3ffe6b2

Log:
Merge branch 'PHP-5.3' into PHP-5.4

* PHP-5.3:
  Fix memleak in CLI

Conflicts:
        sapi/cli/php_cli.c

Changed paths:
  MM  sapi/cli/php_cli.c


Diff:
diff --cc sapi/cli/php_cli.c
index 205b9db,d63ee1a..2cdd1aa
--- a/sapi/cli/php_cli.c
+++ b/sapi/cli/php_cli.c
@@@ -1173,205 -1367,20 +1173,208 @@@ out
        if (request_started) {
                php_request_shutdown((void *) 0);
        }
+       if (translated_path) {
+               free(translated_path);
+       }
 -      if (exit_status == 0) {
 -              exit_status = EG(exit_status);
 +      return exit_status;
 +err:
 +      sapi_deactivate(TSRMLS_C);
 +      zend_ini_deactivate(TSRMLS_C);
 +      exit_status = 1;
 +      goto out;
 +}
 +/* }}} */
 +
 +/* {{{ main
 + */
 +#ifdef PHP_CLI_WIN32_NO_CONSOLE
 +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR 
lpCmdLine, int nShowCmd)
 +#else
 +int main(int argc, char *argv[])
 +#endif
 +{
 +#ifdef ZTS
 +      void ***tsrm_ls;
 +#endif
 +#ifdef PHP_CLI_WIN32_NO_CONSOLE
 +      int argc = __argc;
 +      char **argv = __argv;
 +#endif
 +      int c;
 +      int exit_status = SUCCESS;
 +      int module_started = 0, sapi_started = 0;
 +      char *php_optarg = NULL;
 +      int php_optind = 1, use_extended_info = 0;
 +      char *ini_path_override = NULL;
 +      char *ini_entries = NULL;
 +      int ini_entries_len = 0;
 +      int ini_ignore = 0;
 +      sapi_module_struct *sapi_module = &cli_sapi_module;
 +
 +      cli_sapi_module.additional_functions = additional_functions;
 +
 +#if defined(PHP_WIN32) && defined(_DEBUG) && defined(PHP_WIN32_DEBUG_HEAP)
 +      {
 +              int tmp_flag;
 +              _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
 +              _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
 +              _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
 +              _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
 +              _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
 +              _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
 +              tmp_flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
 +              tmp_flag |= _CRTDBG_DELAY_FREE_MEM_DF;
 +              tmp_flag |= _CRTDBG_LEAK_CHECK_DF;
 +
 +              _CrtSetDbgFlag(tmp_flag);
 +      }
 +#endif
 +
 +#ifdef HAVE_SIGNAL_H
 +#if defined(SIGPIPE) && defined(SIG_IGN)
 +      signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so
 +                                                              that sockets 
created via fsockopen()
 +                                                              don't kill PHP 
if the remote site
 +                                                              closes it.  in 
apache|apxs mode apache
 +                                                              does that for 
us!  th...@thieso.net
 +                                                              20000419 */
 +#endif
 +#endif
 +
 +
 +#ifdef ZTS
 +      tsrm_startup(1, 1, 0, NULL);
 +      tsrm_ls = ts_resource(0);
 +#endif
 +
 +#ifdef PHP_WIN32
 +      _fmode = _O_BINARY;                     /*sets default for file streams 
to binary */
 +      setmode(_fileno(stdin), O_BINARY);              /* make the stdio mode 
be binary */
 +      setmode(_fileno(stdout), O_BINARY);             /* make the stdio mode 
be binary */
 +      setmode(_fileno(stderr), O_BINARY);             /* make the stdio mode 
be binary */
 +#endif
 +
 +      while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 
0, 2))!=-1) {
 +              switch (c) {
 +                      case 'c':
 +                              if (ini_path_override) {
 +                                      free(ini_path_override);
 +                              }
 +                              ini_path_override = strdup(php_optarg);
 +                              break;
 +                      case 'n':
 +                              ini_ignore = 1;
 +                              break;
 +                      case 'd': {
 +                              /* define ini entries on command line */
 +                              int len = strlen(php_optarg);
 +                              char *val;
 +
 +                              if ((val = strchr(php_optarg, '='))) {
 +                                      val++;
 +                                      if (!isalnum(*val) && *val != '"' && 
*val != '\'' && *val != '\0') {
 +                                              ini_entries = 
realloc(ini_entries, ini_entries_len + len + sizeof("\"\"\n\0"));
 +                                              memcpy(ini_entries + 
ini_entries_len, php_optarg, (val - php_optarg));
 +                                              ini_entries_len += (val - 
php_optarg);
 +                                              memcpy(ini_entries + 
ini_entries_len, "\"", 1);
 +                                              ini_entries_len++;
 +                                              memcpy(ini_entries + 
ini_entries_len, val, len - (val - php_optarg));
 +                                              ini_entries_len += len - (val - 
php_optarg);
 +                                              memcpy(ini_entries + 
ini_entries_len, "\"\n\0", sizeof("\"\n\0"));
 +                                              ini_entries_len += 
sizeof("\n\0\"") - 2;
 +                                      } else {
 +                                              ini_entries = 
realloc(ini_entries, ini_entries_len + len + sizeof("\n\0"));
 +                                              memcpy(ini_entries + 
ini_entries_len, php_optarg, len);
 +                                              memcpy(ini_entries + 
ini_entries_len + len, "\n\0", sizeof("\n\0"));
 +                                              ini_entries_len += len + 
sizeof("\n\0") - 2;
 +                                      }
 +                              } else {
 +                                      ini_entries = realloc(ini_entries, 
ini_entries_len + len + sizeof("=1\n\0"));
 +                                      memcpy(ini_entries + ini_entries_len, 
php_optarg, len);
 +                                      memcpy(ini_entries + ini_entries_len + 
len, "=1\n\0", sizeof("=1\n\0"));
 +                                      ini_entries_len += len + 
sizeof("=1\n\0") - 2;
 +                              }
 +                              break;
 +                      }
 +#ifndef PHP_CLI_WIN32_NO_CONSOLE
 +                      case 'S':
 +                              sapi_module = &cli_server_sapi_module;
 +                              break;
 +#endif
 +                      case 'h': /* help & quit */
 +                      case '?':
 +                              php_cli_usage(argv[0]);
 +                              goto out;
 +                      case 'i': case 'v': case 'm':
 +                              sapi_module = &cli_sapi_module;
 +                              goto exit_loop;
 +                      case 'e': /* enable extended info output */
 +                              use_extended_info = 1;
 +                              break;
 +              }
 +      }
 +exit_loop:
 +
 +      sapi_module->ini_defaults = sapi_cli_ini_defaults;
 +      sapi_module->php_ini_path_override = ini_path_override;
 +      sapi_module->phpinfo_as_text = 1;
 +      sapi_module->php_ini_ignore_cwd = 1;
 +      sapi_startup(sapi_module);
 +      sapi_started = 1;
 +
 +      sapi_module->php_ini_ignore = ini_ignore;
 +
 +      sapi_module->executable_location = argv[0];
 +
 +      if (sapi_module == &cli_sapi_module) {
 +              if (ini_entries) {
 +                      ini_entries = realloc(ini_entries, ini_entries_len + 
sizeof(HARDCODED_INI));
 +                      memmove(ini_entries + sizeof(HARDCODED_INI) - 2, 
ini_entries, ini_entries_len + 1);
 +                      memcpy(ini_entries, HARDCODED_INI, 
sizeof(HARDCODED_INI) - 2);
 +              } else {
 +                      ini_entries = malloc(sizeof(HARDCODED_INI));
 +                      memcpy(ini_entries, HARDCODED_INI, 
sizeof(HARDCODED_INI));
 +              }
 +              ini_entries_len += sizeof(HARDCODED_INI) - 2;
        }
 -out_err:      
 -      if (cli_sapi_module.php_ini_path_override) {
 -              free(cli_sapi_module.php_ini_path_override);
 +
 +      sapi_module->ini_entries = ini_entries;
 +
 +      /* startup after we get the above ini override se we get things right */
 +      if (sapi_module->startup(sapi_module) == FAILURE) {
 +              /* there is no way to see if we must call zend_ini_deactivate()
 +               * since we cannot check if EG(ini_directives) has been 
initialised
 +               * because the executor's constructor does not set initialize 
it.
 +               * Apart from that there seems no need for 
zend_ini_deactivate() yet.
 +               * So we goto out_err.*/
 +              exit_status = 1;
 +              goto out;
        }
 -      if (cli_sapi_module.ini_entries) {
 -              free(cli_sapi_module.ini_entries);
 +      module_started = 1;
 +      
 +      /* -e option */
 +      if (use_extended_info) {
 +              CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO;
        }
  
 +      zend_first_try {
 +#ifndef PHP_CLI_WIN32_NO_CONSOLE
 +              if (sapi_module == &cli_sapi_module) {
 +#endif
 +                      exit_status = do_cli(argc, argv TSRMLS_CC);
 +#ifndef PHP_CLI_WIN32_NO_CONSOLE
 +              } else {
 +                      exit_status = do_cli_server(argc, argv TSRMLS_CC);
 +              }
 +#endif
 +      } zend_end_try();
 +out:
 +      if (ini_path_override) {
 +              free(ini_path_override);
 +      }
 +      if (ini_entries) {
 +              free(ini_entries);
 +      }
        if (module_started) {
                php_module_shutdown(TSRMLS_C);
        }


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to