From 4ba128ad333356b23a4bff4acf78b1234a5bf5e0 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Fri, 22 Dec 2023 22:53:42 +0000 Subject: [PATCH] [v1.04][X86] Fix incorrect free in AMD CPUs --- src/common/cpu.c | 2 +- src/x86/cpuid.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/common/cpu.c b/src/common/cpu.c index 1987420..a7d53ca 100644 --- a/src/common/cpu.c +++ b/src/common/cpu.c @@ -194,7 +194,7 @@ void init_topology_struct(struct topology* topo, struct cache* cach) { topo->sockets = 0; #ifdef ARCH_X86 topo->smt_available = 0; - topo->apic = emalloc(sizeof(struct apic)); + topo->apic = ecalloc(1, sizeof(struct apic)); #endif #endif } diff --git a/src/x86/cpuid.c b/src/x86/cpuid.c index 2f93a59..4ee8972 100644 --- a/src/x86/cpuid.c +++ b/src/x86/cpuid.c @@ -1170,8 +1170,10 @@ void print_raw(struct cpuInfo* cpu) { } void free_topo_struct(struct topology* topo) { - free(topo->apic->cache_select_mask); - free(topo->apic->cache_id_apic); + if(topo->apic->cache_select_mask != NULL) + free(topo->apic->cache_select_mask); + if(topo->apic->cache_id_apic != NULL) + free(topo->apic->cache_id_apic); free(topo->apic); free(topo); }