Browse Source

refactor: prevent a useless allocation (#895)

* refactor: prevent a useless allocation

* cs
Kévin Dunglas 8 months ago
parent
commit
8ff6cfdda8
1 changed files with 3 additions and 8 deletions
  1. 3 8
      frankenphp.c

+ 3 - 8
frankenphp.c

@@ -733,9 +733,7 @@ static void *manager_thread(void *arg) {
     exit(EXIT_FAILURE);
   }
 
-  int num_threads = *((int *)arg);
-  free(arg);
-  arg = NULL;
+  intptr_t num_threads = (intptr_t)arg;
 
 #ifdef ZTS
 #if (PHP_VERSION_ID >= 80300)
@@ -796,11 +794,8 @@ static void *manager_thread(void *arg) {
 int frankenphp_init(int num_threads) {
   pthread_t thread;
 
-  int *num_threads_ptr = calloc(1, sizeof(int));
-  *num_threads_ptr = num_threads;
-
-  if (pthread_create(&thread, NULL, *manager_thread, (void *)num_threads_ptr) !=
-      0) {
+  if (pthread_create(&thread, NULL, *manager_thread,
+                     (void *)(intptr_t)num_threads) != 0) {
     go_shutdown();
 
     return -1;