2
0
mirror of https://github.com/Dr-Noob/cpufetch synced 2025-08-31 06:15:08 +00:00

Fix memory leaks. Add debug message when microarch is unknown

This commit is contained in:
Dr-Noob
2020-09-01 11:32:08 +02:00
parent de8952b4ea
commit 5cca6df218
7 changed files with 27 additions and 14 deletions

View File

@@ -909,10 +909,12 @@ char* get_str_freq(struct frequency* freq) {
return string;
}
void print_levels(struct cpuInfo* cpu, char* cpu_name) {
printf("%s\n", cpu_name);
void print_levels(struct cpuInfo* cpu) {
printf("%s\n", cpu->cpu_name);
printf("- Max standart level: 0x%.8X\n", cpu->maxLevels);
printf("- Max extended level: 0x%.8X\n", cpu->maxExtendedLevels);
free_cpuinfo_struct(cpu);
}
void free_topo_struct(struct topology* topo) {
@@ -931,3 +933,9 @@ void free_cache_struct(struct cache* cach) {
void free_freq_struct(struct frequency* freq) {
free(freq);
}
void free_cpuinfo_struct(struct cpuInfo* cpu) {
free_uarch_struct(cpu->arch);
free(cpu->cpu_name);
free(cpu);
}

View File

@@ -97,12 +97,12 @@ char* get_str_topology(struct cpuInfo* cpu, struct topology* topo, bool dual_soc
char* get_str_peak_performance(struct cpuInfo* cpu, struct topology* topo, int64_t freq);
void print_levels(struct cpuInfo* cpu, char* cpu_name);
void print_levels(struct cpuInfo* cpu);
void free_cpuinfo_struct(struct cpuInfo* cpu);
void free_cache_struct(struct cache* cach);
void free_topo_struct(struct topology* topo);
void free_freq_struct(struct frequency* freq);
void free_cpuinfo_struct(struct cpuInfo* cpu);
void debug_cpu_info(struct cpuInfo* cpu);
void debug_cache(struct cache* cach);

View File

@@ -51,7 +51,7 @@ void printBug(const char *fmt, ...) {
vsnprintf(buffer,buffer_size, fmt, args);
va_end(args);
fprintf(stderr,RED "[ERROR]: "RESET "%s\n",buffer);
fprintf(stderr,"Please, create a new issue with this error message and your CPU in https://github.com/Dr-Noob/cpufetch/issues\n");
fprintf(stderr,"Please, create a new issue with this error message and your CPU model in https://github.com/Dr-Noob/cpufetch/issues\n");
}
void set_log_level(bool verbose) {

View File

@@ -6,7 +6,7 @@
#include "cpuid.h"
#include "global.h"
static const char* VERSION = "0.65";
static const char* VERSION = "0.66";
void print_help(char *argv[]) {
printf("Usage: %s [--version] [--help] [--levels] [--style \"fancy\"|\"retro\"|\"legacy\"] [--color \"intel\"|\"amd\"|'R,G,B:R,G,B:R,G,B:R,G,B']\n\n\
@@ -62,7 +62,7 @@ int main(int argc, char* argv[]) {
if(show_levels()) {
print_version();
print_levels(cpu, get_str_cpu_name(cpu));
print_levels(cpu);
return EXIT_SUCCESS;
}

View File

@@ -363,8 +363,6 @@ bool print_cpufetch(struct cpuInfo* cpu, struct cache* cach, struct frequency* f
print_ascii(art);
free(cpu_name);
free(uarch);
free(manufacturing_process);
free(max_frequency);
free(sockets);
@@ -376,15 +374,15 @@ bool print_cpufetch(struct cpuInfo* cpu, struct cache* cach, struct frequency* f
free(l1d);
free(l2);
free(l3);
free(pp);
free(cpu);
free(pp);
free(art);
if(cs != NULL) free_colors_struct(cs);
free_cache_struct(cach);
free_topo_struct(topo);
free_freq_struct(freq);
free_cpuinfo_struct(cpu);
return true;
}

View File

@@ -4,6 +4,7 @@
#include <string.h>
#include "uarch.h"
#include "global.h"
/*
* - cpuid codes are based on Todd Allen's cpuid program
@@ -110,10 +111,10 @@ struct uarch {
#define UARCH_START if (false) {}
#define CHECK_UARCH(arch, ef_, f_, em_, m_, s_, str, uarch, process) \
else if (ef_ == ef && f_ == f && (em_ == NA || em_ == em) && (m_ == NA || m_ == m) && (s_ == NA || s_ == s)) fill_uarch(arch, str, uarch, process);
#define UARCH_END else { arch->uarch = UARCH_UNKNOWN; }
#define UARCH_END else { printBug("Unknown microarchitecture detected: M=0x%.8X EM=0x%.8X F=0x%.8X EF=0x%.8X S=0x%.8X", m, em, f, ef, s); fill_uarch(arch, "Unknown", UARCH_UNKNOWN, 0); }
void fill_uarch(struct uarch* arch, char* str, MICROARCH u, uint32_t process) {
arch->uarch_str = malloc(sizeof(char) * strlen(str));
arch->uarch_str = malloc(sizeof(char) * (strlen(str)+1));
strcpy(arch->uarch_str, str);
arch->uarch = u;
arch->process= process;
@@ -389,3 +390,8 @@ char* get_str_process(struct cpuInfo* cpu) {
return str;
}
void free_uarch_struct(struct uarch* arch) {
free(arch->uarch_str);
free(arch);
}

View File

@@ -12,5 +12,6 @@ bool vpus_are_AVX512(struct cpuInfo* cpu);
int get_number_of_vpus(struct cpuInfo* cpu);
char* get_str_uarch(struct cpuInfo* cpu);
char* get_str_process(struct cpuInfo* cpu);
void free_uarch_struct(struct uarch* arch);
#endif