diff options
| author | Joseph Hunkeler <jhunkeler@gmail.com> | 2026-05-10 21:45:54 -0400 |
|---|---|---|
| committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2026-05-11 15:56:09 -0400 |
| commit | c594e4632a9125497fc86f2a79dde50c86c514fc (patch) | |
| tree | 61096698860aa9ee1fc8311979cc6175ba2ecdbe /src/lib | |
| parent | 3eddcfe9d11e6feba000fab54288124cb24f1899 (diff) | |
| download | stasis-c594e4632a9125497fc86f2a79dde50c86c514fc.tar.gz | |
Allocate heap instead of mmapping the task's command string
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/core/multiprocessing.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/lib/core/multiprocessing.c b/src/lib/core/multiprocessing.c index 5a6767f..f33b38d 100644 --- a/src/lib/core/multiprocessing.c +++ b/src/lib/core/multiprocessing.c @@ -245,8 +245,12 @@ struct MultiProcessingTask *mp_pool_task(struct MultiProcessingPool *pool, const // Record the command(s) SYSDEBUG("%s", "mmap() slot command"); - slot->cmd_len = (strlen(cmd) * sizeof(*cmd)) + 1; - slot->cmd = mmap(NULL, slot->cmd_len, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); + slot->cmd_len = strlen(cmd) + 1; + slot->cmd = calloc(slot->cmd_len, sizeof(*slot->cmd)); + if (!slot->cmd) { + SYSERROR("Failed to allocate memory for slot command"); + return NULL; + } memset(slot->cmd, 0, slot->cmd_len); snprintf(slot->cmd, slot->cmd_len, "%s", cmd); @@ -591,14 +595,14 @@ void mp_pool_free(struct MultiProcessingPool **pool) { semaphore_destroy(&(*pool)->semaphore); } - // Unmap all pool tasks + // Free all task commands if ((*pool)->task) { - if ((*pool)->task->cmd) { - if (munmap((*pool)->task->cmd, (*pool)->task->cmd_len) < 0) { - perror("munmap"); - } + for (size_t i = 0; i < (*pool)->num_alloc + 1; i++) { + struct MultiProcessingTask *task = &(*pool)->task[i]; + guard_free(task->cmd); } - if (munmap((*pool)->task, sizeof(*(*pool)->task) * (*pool)->num_alloc) < 0) { + // Unmap the task array + if (munmap((*pool)->task, sizeof(*(*pool)->task) * (*pool)->num_alloc + 1) < 0) { perror("munmap"); } } |
