mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 07:50:40 +01:00
Fixed memory leaks and unitialized variables
This commit is contained in:
10
01h.c
10
01h.c
@@ -72,6 +72,7 @@ void initializeCpuInfo(struct cpuInfo* cpu) {
|
||||
#define MASK 0xFF
|
||||
VENDOR getCPUVendor(unsigned eax,unsigned ebx,unsigned ecx,unsigned edx) {
|
||||
char name[13];
|
||||
memset(name,0,13);
|
||||
name[__COUNTER__] = ebx & MASK;
|
||||
name[__COUNTER__] = (ebx>>8) & MASK;
|
||||
name[__COUNTER__] = (ebx>>16) & MASK;
|
||||
@@ -87,8 +88,6 @@ VENDOR getCPUVendor(unsigned eax,unsigned ebx,unsigned ecx,unsigned edx) {
|
||||
name[__COUNTER__] = (ecx>>16) & MASK;
|
||||
name[__COUNTER__] = (ecx>>24) & MASK;
|
||||
|
||||
name[__COUNTER__] = '\0';
|
||||
|
||||
if(strcmp(VENDOR_INTEL_STRING,name) == 0)
|
||||
return VENDOR_INTEL;
|
||||
|
||||
@@ -102,7 +101,10 @@ struct cpuInfo* getCPUInfo() {
|
||||
struct cpuInfo* cpu = malloc(sizeof(struct cpuInfo));
|
||||
initializeCpuInfo(cpu);
|
||||
|
||||
unsigned eax, ebx, ecx, edx;
|
||||
unsigned eax = 0;
|
||||
unsigned ebx = 0;
|
||||
unsigned ecx = 0;
|
||||
unsigned edx = 0;
|
||||
|
||||
//Get max cpuid level
|
||||
eax = 0x0000000;
|
||||
@@ -278,7 +280,6 @@ char* getString_AVX(struct cpuInfo* cpu) {
|
||||
}
|
||||
|
||||
char* getString_SSE(struct cpuInfo* cpu) {
|
||||
char* string = malloc(sizeof(char)*33+1);
|
||||
int last = 0;
|
||||
int SSE_sl = 4;
|
||||
int SSE2_sl = 5;
|
||||
@@ -287,6 +288,7 @@ char* getString_SSE(struct cpuInfo* cpu) {
|
||||
int SSE4a_sl = 6;
|
||||
int SSE4_1_sl = 7;
|
||||
int SSE4_2_sl = 7;
|
||||
char* string = malloc(sizeof(char)*SSE_sl+SSE2_sl+SSE3_sl+SSSE3_sl+SSE4a_sl+SSE4_1_sl+SSE4_2_sl+1);
|
||||
|
||||
if(cpu->SSE == BOOLEAN_TRUE) {
|
||||
snprintf(string+last,SSE_sl+1,"SSE,");
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
#include "extended.h"
|
||||
|
||||
char* getString_CPUName() {
|
||||
unsigned eax, ebx, ecx, edx;
|
||||
unsigned eax = 0;
|
||||
unsigned ebx = 0;
|
||||
unsigned ecx = 0;
|
||||
unsigned edx = 0;
|
||||
|
||||
char name[64];
|
||||
memset(name,0,64);
|
||||
|
||||
|
||||
4
main.c
4
main.c
@@ -44,6 +44,7 @@ int main() {
|
||||
char* l1 = getString_L1(cach);
|
||||
char* l2 = getString_L2(cach);
|
||||
char* l3 = getString_L3(cach);
|
||||
char* pp = getPeakPerformance(cpu,getFrequency(freq));
|
||||
|
||||
print_ascii(ascii,__COUNTER__);
|
||||
printf("\n");
|
||||
@@ -91,7 +92,7 @@ int main() {
|
||||
print_text(ascii,TITLE_L3,l3);
|
||||
|
||||
print_ascii(ascii,__COUNTER__);
|
||||
print_text(ascii,TITLE_PEAK,getPeakPerformance(cpu,getFrequency(freq)));
|
||||
print_text(ascii,TITLE_PEAK,pp);
|
||||
|
||||
print_ascii(ascii,__COUNTER__);
|
||||
printf("\n");
|
||||
@@ -116,6 +117,7 @@ int main() {
|
||||
free(l1);
|
||||
free(l2);
|
||||
free(l3);
|
||||
free(pp);
|
||||
|
||||
free(cpu);
|
||||
free(ascii);
|
||||
|
||||
Reference in New Issue
Block a user