Fixed memory leaks and unitialized variables

This commit is contained in:
Dr-Noob
2018-03-30 21:39:15 +02:00
parent c0ad4283e9
commit cad0778fd6
4 changed files with 15 additions and 6 deletions

10
01h.c
View File

@@ -72,6 +72,7 @@ void initializeCpuInfo(struct cpuInfo* cpu) {
#define MASK 0xFF #define MASK 0xFF
VENDOR getCPUVendor(unsigned eax,unsigned ebx,unsigned ecx,unsigned edx) { VENDOR getCPUVendor(unsigned eax,unsigned ebx,unsigned ecx,unsigned edx) {
char name[13]; char name[13];
memset(name,0,13);
name[__COUNTER__] = ebx & MASK; name[__COUNTER__] = ebx & MASK;
name[__COUNTER__] = (ebx>>8) & MASK; name[__COUNTER__] = (ebx>>8) & MASK;
name[__COUNTER__] = (ebx>>16) & 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>>16) & MASK;
name[__COUNTER__] = (ecx>>24) & MASK; name[__COUNTER__] = (ecx>>24) & MASK;
name[__COUNTER__] = '\0';
if(strcmp(VENDOR_INTEL_STRING,name) == 0) if(strcmp(VENDOR_INTEL_STRING,name) == 0)
return VENDOR_INTEL; return VENDOR_INTEL;
@@ -102,7 +101,10 @@ struct cpuInfo* getCPUInfo() {
struct cpuInfo* cpu = malloc(sizeof(struct cpuInfo)); struct cpuInfo* cpu = malloc(sizeof(struct cpuInfo));
initializeCpuInfo(cpu); initializeCpuInfo(cpu);
unsigned eax, ebx, ecx, edx; unsigned eax = 0;
unsigned ebx = 0;
unsigned ecx = 0;
unsigned edx = 0;
//Get max cpuid level //Get max cpuid level
eax = 0x0000000; eax = 0x0000000;
@@ -278,7 +280,6 @@ char* getString_AVX(struct cpuInfo* cpu) {
} }
char* getString_SSE(struct cpuInfo* cpu) { char* getString_SSE(struct cpuInfo* cpu) {
char* string = malloc(sizeof(char)*33+1);
int last = 0; int last = 0;
int SSE_sl = 4; int SSE_sl = 4;
int SSE2_sl = 5; int SSE2_sl = 5;
@@ -287,6 +288,7 @@ char* getString_SSE(struct cpuInfo* cpu) {
int SSE4a_sl = 6; int SSE4a_sl = 6;
int SSE4_1_sl = 7; int SSE4_1_sl = 7;
int SSE4_2_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) { if(cpu->SSE == BOOLEAN_TRUE) {
snprintf(string+last,SSE_sl+1,"SSE,"); snprintf(string+last,SSE_sl+1,"SSE,");

View File

@@ -3,7 +3,11 @@
#include "extended.h" #include "extended.h"
char* getString_CPUName() { char* getString_CPUName() {
unsigned eax, ebx, ecx, edx; unsigned eax = 0;
unsigned ebx = 0;
unsigned ecx = 0;
unsigned edx = 0;
char name[64]; char name[64];
memset(name,0,64); memset(name,0,64);

4
main.c
View File

@@ -44,6 +44,7 @@ int main() {
char* l1 = getString_L1(cach); char* l1 = getString_L1(cach);
char* l2 = getString_L2(cach); char* l2 = getString_L2(cach);
char* l3 = getString_L3(cach); char* l3 = getString_L3(cach);
char* pp = getPeakPerformance(cpu,getFrequency(freq));
print_ascii(ascii,__COUNTER__); print_ascii(ascii,__COUNTER__);
printf("\n"); printf("\n");
@@ -91,7 +92,7 @@ int main() {
print_text(ascii,TITLE_L3,l3); print_text(ascii,TITLE_L3,l3);
print_ascii(ascii,__COUNTER__); print_ascii(ascii,__COUNTER__);
print_text(ascii,TITLE_PEAK,getPeakPerformance(cpu,getFrequency(freq))); print_text(ascii,TITLE_PEAK,pp);
print_ascii(ascii,__COUNTER__); print_ascii(ascii,__COUNTER__);
printf("\n"); printf("\n");
@@ -116,6 +117,7 @@ int main() {
free(l1); free(l1);
free(l2); free(l2);
free(l3); free(l3);
free(pp);
free(cpu); free(cpu);
free(ascii); free(ascii);

1
udev.c
View File

@@ -109,6 +109,7 @@ long getFrequencyFromFile(char* path) {
printf("error in getFrequencyFromFile\n"); printf("error in getFrequencyFromFile\n");
return NO_CACHE; return NO_CACHE;
} }
fclose(file);
return (long)ret*1000; return (long)ret*1000;
} }