Skip to content

Commit ad99f99

Browse files
committed
sapi/fpm/status: replace variable-length array with emalloc()
According to @cmb69, PHP does not require VLA support (php#10304 (comment)). VLAs are a bad idea for several reasons, so let's get rid of them. This is a continuation of php#10645
1 parent f4313a8 commit ad99f99

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

sapi/fpm/fpm/fpm_status.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ int fpm_status_export_to_zval(zval *status)
6161

6262
/* copy the scoreboard not to bother other processes */
6363
scoreboard = *scoreboard_p;
64-
struct fpm_scoreboard_proc_s procs[scoreboard.nprocs];
64+
struct fpm_scoreboard_proc_s *procs = safe_emalloc(scoreboard.nprocs, sizeof(*procs), 0);
65+
if (procs == NULL) {
66+
return FAILURE;
67+
}
6568

6669
struct fpm_scoreboard_proc_s *proc_p;
6770
for(i=0; i<scoreboard.nprocs; i++) {
@@ -129,6 +132,7 @@ int fpm_status_export_to_zval(zval *status)
129132
add_assoc_long(&fpm_proc_stat, "last-request-memory", procs[i].request_stage == FPM_REQUEST_ACCEPTING ? procs[i].memory : 0);
130133
add_next_index_zval(&fpm_proc_stats, &fpm_proc_stat);
131134
}
135+
efree(procs);
132136
add_assoc_zval(status, "procs", &fpm_proc_stats);
133137
return 0;
134138
}

0 commit comments

Comments
 (0)