From feb6a085373d9808862da6a85888e52fbc4995c9 Mon Sep 17 00:00:00 2001 From: bi4k8 Date: Fri, 5 May 2023 00:42:58 +0000 Subject: [PATCH] freebsd: infallibly allocate 16B buffer on stack there's no need to call calloc() for 16B, nor do we need to error-handle that allocation with exit() --- src/freebsd.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/freebsd.cc b/src/freebsd.cc index c2d8e540..77d9b44a 100644 --- a/src/freebsd.cc +++ b/src/freebsd.cc @@ -551,10 +551,9 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size, return 0; } - freq_sysctl = (char *)calloc(16, sizeof(char)); - if (freq_sysctl == nullptr) { exit(-1); } + char freq_sysctl[16] = {0}; - snprintf(freq_sysctl, 16, "dev.cpu.%d.freq", (cpu - 1)); + snprintf(freq_sysctl, sizeof(freq_sysctl), "dev.cpu.%d.freq", (cpu - 1)); if (GETSYSCTL(freq_sysctl, freq) == 0) { snprintf(p_client_buffer, client_buffer_size, p_format, @@ -563,7 +562,6 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size, snprintf(p_client_buffer, client_buffer_size, p_format, 0.0f); } - free(freq_sysctl); return 1; }