BUGFIX: Fix crash when adding meters and toggling detailed CPU time.

See https://bugzilla.redhat.com/show_bug.cgi?id=987805 for details.
(thanks to Dawid Gajownik for the detailed analysis!)
This commit is contained in:
Hisham Muhammad 2014-01-16 01:40:47 -02:00
parent 4256c23d84
commit c1e0f6e17c
12 changed files with 20 additions and 24 deletions

View File

@ -335,7 +335,6 @@ MeterClass BatteryMeter_class = {
},
.setValues = BatteryMeter_setValues,
.defaultMode = TEXT_METERMODE,
.items = 1,
.total = 100.0,
.attributes = BatteryMeter_attributes,
.name = "Battery",

View File

@ -228,7 +228,7 @@ MeterClass CPUMeter_class = {
},
.setValues = CPUMeter_setValues,
.defaultMode = BAR_METERMODE,
.items = 8,
.maxItems = 8,
.total = 100.0,
.attributes = CPUMeter_attributes,
.name = "CPU",
@ -244,7 +244,6 @@ MeterClass AllCPUsMeter_class = {
.display = CPUMeter_display
},
.defaultMode = CUSTOM_METERMODE,
.items = 1,
.total = 100.0,
.attributes = CPUMeter_attributes,
.name = "AllCPUs",
@ -263,7 +262,6 @@ MeterClass AllCPUs2Meter_class = {
.display = CPUMeter_display
},
.defaultMode = CUSTOM_METERMODE,
.items = 1,
.total = 100.0,
.attributes = CPUMeter_attributes,
.name = "AllCPUs2",
@ -282,7 +280,6 @@ MeterClass LeftCPUsMeter_class = {
.display = CPUMeter_display
},
.defaultMode = CUSTOM_METERMODE,
.items = 1,
.total = 100.0,
.attributes = CPUMeter_attributes,
.name = "LeftCPUs",
@ -301,7 +298,6 @@ MeterClass RightCPUsMeter_class = {
.display = CPUMeter_display
},
.defaultMode = CUSTOM_METERMODE,
.items = 1,
.total = 100.0,
.attributes = CPUMeter_attributes,
.name = "RightCPUs",
@ -320,7 +316,6 @@ MeterClass LeftCPUs2Meter_class = {
.display = CPUMeter_display
},
.defaultMode = CUSTOM_METERMODE,
.items = 1,
.total = 100.0,
.attributes = CPUMeter_attributes,
.name = "LeftCPUs2",
@ -339,7 +334,6 @@ MeterClass RightCPUs2Meter_class = {
.display = CPUMeter_display
},
.defaultMode = CUSTOM_METERMODE,
.items = 1,
.total = 100.0,
.attributes = CPUMeter_attributes,
.name = "RightCPUs2",

View File

@ -8,6 +8,8 @@ What's new in version 1.0.3
(thanks to Jann Horn)
* Further performance improvements due to conditional parsing
of IO data depending on selected fields.
* BUGFIX: Fix crash when adding meters and toggling detailed CPU time.
(thanks to Dawid Gajownik)
What's new in version 1.0.2

View File

@ -34,7 +34,6 @@ MeterClass ClockMeter_class = {
.setValues = ClockMeter_setValues,
.defaultMode = TEXT_METERMODE,
.total = 100.0,
.items = 1,
.attributes = ClockMeter_attributes,
.name = "Clock",
.uiName = "Clock",

View File

@ -32,7 +32,6 @@ MeterClass HostnameMeter_class = {
.setValues = HostnameMeter_setValues,
.defaultMode = TEXT_METERMODE,
.total = 100.0,
.items = 1,
.attributes = HostnameMeter_attributes,
.name = "Hostname",
.uiName = "Hostname",

View File

@ -74,7 +74,7 @@ MeterClass LoadAverageMeter_class = {
},
.setValues = LoadAverageMeter_setValues,
.defaultMode = TEXT_METERMODE,
.items = 3,
.maxItems = 3,
.total = 100.0,
.attributes = LoadAverageMeter_attributes,
.name = "LoadAverage",
@ -90,7 +90,6 @@ MeterClass LoadMeter_class = {
},
.setValues = LoadMeter_setValues,
.defaultMode = TEXT_METERMODE,
.items = 1,
.total = 100.0,
.attributes = LoadMeter_attributes,
.name = "Load",

View File

@ -66,7 +66,7 @@ MeterClass MemoryMeter_class = {
},
.setValues = MemoryMeter_setValues,
.defaultMode = BAR_METERMODE,
.items = 3,
.maxItems = 3,
.total = 100.0,
.attributes = MemoryMeter_attributes,
"Memory",

16
Meter.c
View File

@ -52,12 +52,13 @@ typedef struct MeterClass_ {
const Meter_Draw draw;
const Meter_SetValues setValues;
const int defaultMode;
int items;
const double total;
const int* attributes;
const char* name;
const char* uiName;
const char* caption;
const char maxItems;
char curItems;
} MeterClass;
#define As_Meter(this_) ((MeterClass*)((this_)->super.klass))
@ -70,8 +71,8 @@ typedef struct MeterClass_ {
#define Meter_doneFn(this_) As_Meter(this_)->done
#define Meter_setValues(this_, c_, i_) As_Meter(this_)->setValues((Meter*)(this_), c_, i_)
#define Meter_defaultMode(this_) As_Meter(this_)->defaultMode
#define Meter_getItems(this_) As_Meter(this_)->items
#define Meter_setItems(this_, n_) As_Meter(this_)->items = (n_)
#define Meter_getItems(this_) As_Meter(this_)->curItems
#define Meter_setItems(this_, n_) As_Meter(this_)->curItems = (n_)
#define Meter_attributes(this_) As_Meter(this_)->attributes
#define Meter_name(this_) As_Meter(this_)->name
#define Meter_uiName(this_) As_Meter(this_)->uiName
@ -146,12 +147,17 @@ MeterClass* Meter_types[] = {
};
Meter* Meter_new(ProcessList* pl, int param, MeterClass* type) {
Meter* this = calloc(sizeof(Meter), 1);
Meter* this = calloc(1, sizeof(Meter));
Object_setClass(this, type);
this->h = 1;
this->param = param;
this->pl = pl;
this->values = calloc(sizeof(double), type->items);
char maxItems = type->maxItems;
if (maxItems == 0) {
maxItems = 1;
}
type->curItems = maxItems;
this->values = calloc(maxItems, sizeof(double));
this->total = type->total;
this->caption = strdup(type->caption);
if (Meter_initFn(this))

View File

@ -30,12 +30,13 @@ typedef struct MeterClass_ {
const Meter_Draw draw;
const Meter_SetValues setValues;
const int defaultMode;
int items;
const double total;
const int* attributes;
const char* name;
const char* uiName;
const char* caption;
const char maxItems;
char curItems;
} MeterClass;
#define As_Meter(this_) ((MeterClass*)((this_)->super.klass))
@ -48,8 +49,8 @@ typedef struct MeterClass_ {
#define Meter_doneFn(this_) As_Meter(this_)->done
#define Meter_setValues(this_, c_, i_) As_Meter(this_)->setValues((Meter*)(this_), c_, i_)
#define Meter_defaultMode(this_) As_Meter(this_)->defaultMode
#define Meter_getItems(this_) As_Meter(this_)->items
#define Meter_setItems(this_, n_) As_Meter(this_)->items = (n_)
#define Meter_getItems(this_) As_Meter(this_)->curItems
#define Meter_setItems(this_, n_) As_Meter(this_)->curItems = (n_)
#define Meter_attributes(this_) As_Meter(this_)->attributes
#define Meter_name(this_) As_Meter(this_)->name
#define Meter_uiName(this_) As_Meter(this_)->uiName

View File

@ -66,7 +66,6 @@ MeterClass SwapMeter_class = {
},
.setValues = SwapMeter_setValues,
.defaultMode = BAR_METERMODE,
.items = 1,
.total = 100.0,
.attributes = SwapMeter_attributes,
.name = "Swap",

View File

@ -63,7 +63,6 @@ MeterClass TasksMeter_class = {
},
.setValues = TasksMeter_setValues,
.defaultMode = TEXT_METERMODE,
.items = 1,
.total = 100.0,
.attributes = TasksMeter_attributes,
.name = "Tasks",

View File

@ -56,7 +56,6 @@ MeterClass UptimeMeter_class = {
},
.setValues = UptimeMeter_setValues,
.defaultMode = TEXT_METERMODE,
.items = 1,
.total = 100.0,
.attributes = UptimeMeter_attributes,
.name = "Uptime",