mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
CPU: fix memleaks
This commit is contained in:
+41
-37
@@ -19,47 +19,51 @@ void ffPrintCPU(FFinstance* instance, FFCPUOptions* options)
|
||||
if(cpu.vendor.length == 0 && cpu.name.length == 0 && cpu.coresOnline <= 1)
|
||||
{
|
||||
ffPrintError(instance, FF_CPU_MODULE_NAME, 0, &options->moduleArgs, "No CPU detected");
|
||||
return;
|
||||
}
|
||||
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_CPU_MODULE_NAME, 0, &options->moduleArgs.key);
|
||||
|
||||
if(cpu.name.length > 0)
|
||||
ffStrbufWriteTo(&cpu.name, stdout);
|
||||
else if(cpu.vendor.length > 0)
|
||||
{
|
||||
ffStrbufWriteTo(&cpu.vendor, stdout);
|
||||
fputs(" CPU", stdout);
|
||||
}
|
||||
else
|
||||
fputs("CPU", stdout);
|
||||
|
||||
if(cpu.coresOnline > 1)
|
||||
printf(" (%u)", cpu.coresOnline);
|
||||
|
||||
if(cpu.frequencyMax > 0.0)
|
||||
printf(" @ %.9g GHz", cpu.frequencyMax);
|
||||
|
||||
if(cpu.temperature == cpu.temperature) //FF_CPU_TEMP_UNSET
|
||||
printf(" - %.1f°C", cpu.temperature);
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_CPU_MODULE_NAME, 0, &options->moduleArgs, FF_CPU_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &cpu.name},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &cpu.vendor},
|
||||
{FF_FORMAT_ARG_TYPE_UINT16, &cpu.coresPhysical},
|
||||
{FF_FORMAT_ARG_TYPE_UINT16, &cpu.coresLogical},
|
||||
{FF_FORMAT_ARG_TYPE_UINT16, &cpu.coresOnline},
|
||||
{FF_FORMAT_ARG_TYPE_DOUBLE, &cpu.frequencyMin},
|
||||
{FF_FORMAT_ARG_TYPE_DOUBLE, &cpu.frequencyMax},
|
||||
{FF_FORMAT_ARG_TYPE_DOUBLE, &cpu.temperature}
|
||||
});
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_CPU_MODULE_NAME, 0, &options->moduleArgs.key);
|
||||
|
||||
if(cpu.name.length > 0)
|
||||
ffStrbufWriteTo(&cpu.name, stdout);
|
||||
else if(cpu.vendor.length > 0)
|
||||
{
|
||||
ffStrbufWriteTo(&cpu.vendor, stdout);
|
||||
fputs(" CPU", stdout);
|
||||
}
|
||||
else
|
||||
fputs("CPU", stdout);
|
||||
|
||||
if(cpu.coresOnline > 1)
|
||||
printf(" (%u)", cpu.coresOnline);
|
||||
|
||||
if(cpu.frequencyMax > 0.0)
|
||||
printf(" @ %.9g GHz", cpu.frequencyMax);
|
||||
|
||||
if(cpu.temperature == cpu.temperature) //FF_CPU_TEMP_UNSET
|
||||
printf(" - %.1f°C", cpu.temperature);
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_CPU_MODULE_NAME, 0, &options->moduleArgs, FF_CPU_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &cpu.name},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &cpu.vendor},
|
||||
{FF_FORMAT_ARG_TYPE_UINT16, &cpu.coresPhysical},
|
||||
{FF_FORMAT_ARG_TYPE_UINT16, &cpu.coresLogical},
|
||||
{FF_FORMAT_ARG_TYPE_UINT16, &cpu.coresOnline},
|
||||
{FF_FORMAT_ARG_TYPE_DOUBLE, &cpu.frequencyMin},
|
||||
{FF_FORMAT_ARG_TYPE_DOUBLE, &cpu.frequencyMax},
|
||||
{FF_FORMAT_ARG_TYPE_DOUBLE, &cpu.temperature}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&cpu.name);
|
||||
ffStrbufDestroy(&cpu.vendor);
|
||||
}
|
||||
|
||||
void ffInitCPUOptions(FFCPUOptions* options)
|
||||
|
||||
Reference in New Issue
Block a user