From 2c8c1166d81a5c0fe6f335742ee24319ce60bfa8 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 26 Apr 2023 00:54:48 -0400 Subject: Use static storage * Almost everything returned by the system is immutable * Fixed block_device array initialization and alphabetical sorting * Free memory where possible --- x86.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'x86.c') diff --git a/x86.c b/x86.c index 647d6ac..e7b2f7e 100644 --- a/x86.c +++ b/x86.c @@ -37,26 +37,21 @@ int is_cpu_virtual() { char *get_sys_product() { union regs_t reg; - char *vendor; + static char vendor[255] = {0}; - vendor = NULL; if (is_cpu_virtual()) { - vendor = calloc(255, sizeof(*vendor)); - if (!vendor) { - return NULL; - } CPUID(0x40000000, ®); strncat(vendor, (char *) ®.bytes[1], sizeof(reg.bytes)); rstrip(vendor); } #if defined(__linux__) if (!vendor || !strlen(vendor)) { - vendor = get_sys_dmi_product(); + strcpy(vendor, get_sys_dmi_product()); rstrip(vendor); } #elif defined(__APPLE__) if (!vendor || !strlen(vendor)) { - vendor = get_sys_product_darwin(); + strcpy(vendor, get_sys_product_darwin()); rstrip(vendor); } #endif @@ -89,13 +84,9 @@ unsigned int get_cpu_count() { char *get_cpu_manufacturer() { union regs_t reg; - char *manufacturer; + static char manufacturer[255] = {0}; CPUID(0, ®); - manufacturer = calloc(sizeof(reg.bytes), sizeof(*reg.bytes)); - if (!manufacturer) { - return NULL; - } strncat(manufacturer, (char *) ®.bytes[1], 4); strncat(manufacturer, (char *) ®.bytes[3], 4); strncat(manufacturer, (char *) ®.bytes[2], 4); @@ -104,9 +95,8 @@ char *get_cpu_manufacturer() { char *get_cpu_vendor() { union regs_t reg; - char *vendor; + static char vendor[255] = {0}; - vendor = calloc(sizeof(reg.bytes) * 3, sizeof(*reg.bytes)); for (unsigned int leaf = 2; leaf < 5; leaf++) { CPUID(0x80000000 + leaf, ®); strncat(vendor, (char *) reg.bytes, sizeof(reg.bytes)); -- cgit