@@ -240,6 +240,7 @@ static void proc_open_rsrc_dtor(zend_resource *rsrc)
240240FG (pclose_ret ) = -1 ;
241241#endif
242242_php_free_envp (proc -> env , proc -> is_persistent );
243+ pefree (proc -> pipes , proc -> is_persistent );
243244pefree (proc -> command , proc -> is_persistent );
244245pefree (proc , proc -> is_persistent );
245246
@@ -434,7 +435,8 @@ PHP_FUNCTION(proc_open)
434435zval * descitem = NULL ;
435436zend_string * str_index ;
436437zend_ulong nindex ;
437- struct php_proc_open_descriptor_item descriptors [PHP_PROC_OPEN_MAX_DESCRIPTORS ];
438+ struct php_proc_open_descriptor_item * descriptors = NULL ;
439+ int ndescriptors_array ;
438440#ifdef PHP_WIN32
439441PROCESS_INFORMATION pi ;
440442HANDLE childHandle ;
@@ -499,7 +501,11 @@ PHP_FUNCTION(proc_open)
499501memset (& env , 0 , sizeof (env ));
500502}
501503
502- memset (descriptors , 0 , sizeof (descriptors ));
504+ ndescriptors_array = zend_hash_num_elements (Z_ARRVAL_P (descriptorspec ));
505+
506+ descriptors = safe_emalloc (sizeof (struct php_proc_open_descriptor_item ), ndescriptors_array , 0 );
507+
508+ memset (descriptors , 0 , sizeof (struct php_proc_open_descriptor_item ) * ndescriptors_array );
503509
504510#ifdef PHP_WIN32
505511/* we use this to allow the child to inherit handles */
@@ -669,9 +675,7 @@ PHP_FUNCTION(proc_open)
669675goto exit_fail ;
670676}
671677}
672-
673- if (++ ndesc == PHP_PROC_OPEN_MAX_DESCRIPTORS )
674- break ;
678+ ndesc ++ ;
675679} ZEND_HASH_FOREACH_END ();
676680
677681#ifdef PHP_WIN32
@@ -875,6 +879,7 @@ PHP_FUNCTION(proc_open)
875879proc = (struct php_process_handle * )pemalloc (sizeof (struct php_process_handle ), is_persistent );
876880proc -> is_persistent = is_persistent ;
877881proc -> command = command ;
882+ proc -> pipes = pemalloc (sizeof (zend_resource * ) * ndesc , is_persistent );
878883proc -> npipes = ndesc ;
879884proc -> child = child ;
880885#ifdef PHP_WIN32
@@ -952,10 +957,12 @@ PHP_FUNCTION(proc_open)
952957}
953958}
954959
960+ efree (descriptors );
955961ZVAL_RES (return_value , zend_register_resource (proc , le_proc_open ));
956962return ;
957963
958964exit_fail :
965+ efree (descriptors );
959966_php_free_envp (env , is_persistent );
960967pefree (command , is_persistent );
961968#if PHP_CAN_DO_PTS
0 commit comments