Skip to content

Commit ba54a46

Browse files
committed
Remove is_persistent flag from proc_open implementation
We don't support persistent proc_open handles and have no plan to suppor them. The mixture of persistent and non-persistent allocations functions in this code is somewhat confusing to read.
1 parent ffcc813 commit ba54a46

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

ext/standard/proc_open.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
static int le_proc_open;
6565

6666
/* {{{ _php_array_to_envp */
67-
static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent)
67+
static php_process_env_t _php_array_to_envp(zval *environment)
6868
{
6969
zval *element;
7070
php_process_env_t env;
@@ -86,9 +86,9 @@ static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent
8686

8787
if (cnt < 1) {
8888
#ifndef PHP_WIN32
89-
env.envarray = (char **) pecalloc(1, sizeof(char *), is_persistent);
89+
env.envarray = (char **) ecalloc(1, sizeof(char *));
9090
#endif
91-
env.envp = (char *) pecalloc(4, 1, is_persistent);
91+
env.envp = (char *) ecalloc(4, 1);
9292
return env;
9393
}
9494

@@ -115,9 +115,9 @@ static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent
115115
} ZEND_HASH_FOREACH_END();
116116

117117
#ifndef PHP_WIN32
118-
ep = env.envarray = (char **) pecalloc(cnt + 1, sizeof(char *), is_persistent);
118+
ep = env.envarray = (char **) ecalloc(cnt + 1, sizeof(char *));
119119
#endif
120-
p = env.envp = (char *) pecalloc(sizeenv + 4, 1, is_persistent);
120+
p = env.envp = (char *) ecalloc(sizeenv + 4, 1);
121121

122122
ZEND_HASH_FOREACH_STR_KEY_PTR(env_hash, key, str) {
123123
#ifndef PHP_WIN32
@@ -147,15 +147,15 @@ static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent
147147
/* }}} */
148148

149149
/* {{{ _php_free_envp */
150-
static void _php_free_envp(php_process_env_t env, int is_persistent)
150+
static void _php_free_envp(php_process_env_t env)
151151
{
152152
#ifndef PHP_WIN32
153153
if (env.envarray) {
154-
pefree(env.envarray, is_persistent);
154+
efree(env.envarray);
155155
}
156156
#endif
157157
if (env.envp) {
158-
pefree(env.envp, is_persistent);
158+
efree(env.envp);
159159
}
160160
}
161161
/* }}} */
@@ -214,10 +214,10 @@ static void proc_open_rsrc_dtor(zend_resource *rsrc)
214214
#else
215215
FG(pclose_ret) = -1;
216216
#endif
217-
_php_free_envp(proc->env, proc->is_persistent);
218-
pefree(proc->pipes, proc->is_persistent);
219-
pefree(proc->command, proc->is_persistent);
220-
pefree(proc, proc->is_persistent);
217+
_php_free_envp(proc->env);
218+
efree(proc->pipes);
219+
efree(proc->command);
220+
efree(proc);
221221

222222
}
223223
/* }}} */
@@ -507,7 +507,6 @@ PHP_FUNCTION(proc_open)
507507
#endif
508508
php_process_id_t child;
509509
struct php_process_handle *proc;
510-
int is_persistent = 0; /* TODO: ensure that persistent procs will work */
511510
#if PHP_CAN_DO_PTS
512511
php_file_descriptor_t dev_ptmx = -1; /* master */
513512
php_file_descriptor_t slave_pty = -1;
@@ -550,7 +549,7 @@ PHP_FUNCTION(proc_open)
550549
}
551550

552551
if (i == 0) {
553-
command = pestrdup(ZSTR_VAL(arg_str), is_persistent);
552+
command = estrdup(ZSTR_VAL(arg_str));
554553
}
555554

556555
argv[i++] = estrdup(ZSTR_VAL(arg_str));
@@ -563,7 +562,7 @@ PHP_FUNCTION(proc_open)
563562
#endif
564563
} else {
565564
convert_to_string(command_zv);
566-
command = pestrdup(Z_STRVAL_P(command_zv), is_persistent);
565+
command = estrdup(Z_STRVAL_P(command_zv));
567566
}
568567

569568
#ifdef PHP_WIN32
@@ -607,7 +606,7 @@ PHP_FUNCTION(proc_open)
607606
#endif
608607

609608
if (environment) {
610-
env = _php_array_to_envp(environment, is_persistent);
609+
env = _php_array_to_envp(environment);
611610
}
612611

613612
ndescriptors_array = zend_hash_num_elements(Z_ARRVAL_P(descriptorspec));
@@ -1087,10 +1086,9 @@ PHP_FUNCTION(proc_open)
10871086
goto exit_fail;
10881087
}
10891088

1090-
proc = (struct php_process_handle*)pemalloc(sizeof(struct php_process_handle), is_persistent);
1091-
proc->is_persistent = is_persistent;
1089+
proc = (struct php_process_handle*) emalloc(sizeof(struct php_process_handle));
10921090
proc->command = command;
1093-
proc->pipes = pemalloc(sizeof(zend_resource *) * ndesc, is_persistent);
1091+
proc->pipes = emalloc(sizeof(zend_resource *) * ndesc);
10941092
proc->npipes = ndesc;
10951093
proc->child = child;
10961094
#ifdef PHP_WIN32
@@ -1182,9 +1180,9 @@ PHP_FUNCTION(proc_open)
11821180
if (descriptors) {
11831181
efree(descriptors);
11841182
}
1185-
_php_free_envp(env, is_persistent);
1183+
_php_free_envp(env);
11861184
if (command) {
1187-
pefree(command, is_persistent);
1185+
efree(command);
11881186
}
11891187
#ifdef PHP_WIN32
11901188
free(cwdw);

0 commit comments

Comments
 (0)