From cad0778fd6d155b33aa6539d333786dfafe60e2e Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Fri, 30 Mar 2018 21:39:15 +0200 Subject: [PATCH] Fixed memory leaks and unitialized variables --- 01h.c | 10 ++++++---- extended.c | 6 +++++- main.c | 4 +++- udev.c | 1 + 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/01h.c b/01h.c index 8aeac4d..b63217a 100644 --- a/01h.c +++ b/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,"); diff --git a/extended.c b/extended.c index 1d9a7c6..779bff0 100644 --- a/extended.c +++ b/extended.c @@ -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); diff --git a/main.c b/main.c index c77f772..43b2a5c 100644 --- a/main.c +++ b/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); diff --git a/udev.c b/udev.c index cfb66f2..388508e 100644 --- a/udev.c +++ b/udev.c @@ -109,6 +109,7 @@ long getFrequencyFromFile(char* path) { printf("error in getFrequencyFromFile\n"); return NO_CACHE; } + fclose(file); return (long)ret*1000; }