Commit c1e0f6e1 authored by Hisham Muhammad's avatar Hisham Muhammad
Browse files

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!)
parent 4256c23d
...@@ -335,7 +335,6 @@ MeterClass BatteryMeter_class = { ...@@ -335,7 +335,6 @@ MeterClass BatteryMeter_class = {
}, },
.setValues = BatteryMeter_setValues, .setValues = BatteryMeter_setValues,
.defaultMode = TEXT_METERMODE, .defaultMode = TEXT_METERMODE,
.items = 1,
.total = 100.0, .total = 100.0,
.attributes = BatteryMeter_attributes, .attributes = BatteryMeter_attributes,
.name = "Battery", .name = "Battery",
......
...@@ -228,7 +228,7 @@ MeterClass CPUMeter_class = { ...@@ -228,7 +228,7 @@ MeterClass CPUMeter_class = {
}, },
.setValues = CPUMeter_setValues, .setValues = CPUMeter_setValues,
.defaultMode = BAR_METERMODE, .defaultMode = BAR_METERMODE,
.items = 8, .maxItems = 8,
.total = 100.0, .total = 100.0,
.attributes = CPUMeter_attributes, .attributes = CPUMeter_attributes,
.name = "CPU", .name = "CPU",
...@@ -244,7 +244,6 @@ MeterClass AllCPUsMeter_class = { ...@@ -244,7 +244,6 @@ MeterClass AllCPUsMeter_class = {
.display = CPUMeter_display .display = CPUMeter_display
}, },
.defaultMode = CUSTOM_METERMODE, .defaultMode = CUSTOM_METERMODE,
.items = 1,
.total = 100.0, .total = 100.0,
.attributes = CPUMeter_attributes, .attributes = CPUMeter_attributes,
.name = "AllCPUs", .name = "AllCPUs",
...@@ -263,7 +262,6 @@ MeterClass AllCPUs2Meter_class = { ...@@ -263,7 +262,6 @@ MeterClass AllCPUs2Meter_class = {
.display = CPUMeter_display .display = CPUMeter_display
}, },
.defaultMode = CUSTOM_METERMODE, .defaultMode = CUSTOM_METERMODE,
.items = 1,
.total = 100.0, .total = 100.0,
.attributes = CPUMeter_attributes, .attributes = CPUMeter_attributes,
.name = "AllCPUs2", .name = "AllCPUs2",
...@@ -282,7 +280,6 @@ MeterClass LeftCPUsMeter_class = { ...@@ -282,7 +280,6 @@ MeterClass LeftCPUsMeter_class = {
.display = CPUMeter_display .display = CPUMeter_display
}, },
.defaultMode = CUSTOM_METERMODE, .defaultMode = CUSTOM_METERMODE,
.items = 1,
.total = 100.0, .total = 100.0,
.attributes = CPUMeter_attributes, .attributes = CPUMeter_attributes,
.name = "LeftCPUs", .name = "LeftCPUs",
...@@ -301,7 +298,6 @@ MeterClass RightCPUsMeter_class = { ...@@ -301,7 +298,6 @@ MeterClass RightCPUsMeter_class = {
.display = CPUMeter_display .display = CPUMeter_display
}, },
.defaultMode = CUSTOM_METERMODE, .defaultMode = CUSTOM_METERMODE,
.items = 1,
.total = 100.0, .total = 100.0,
.attributes = CPUMeter_attributes, .attributes = CPUMeter_attributes,
.name = "RightCPUs", .name = "RightCPUs",
...@@ -320,7 +316,6 @@ MeterClass LeftCPUs2Meter_class = { ...@@ -320,7 +316,6 @@ MeterClass LeftCPUs2Meter_class = {
.display = CPUMeter_display .display = CPUMeter_display
}, },
.defaultMode = CUSTOM_METERMODE, .defaultMode = CUSTOM_METERMODE,
.items = 1,
.total = 100.0, .total = 100.0,
.attributes = CPUMeter_attributes, .attributes = CPUMeter_attributes,
.name = "LeftCPUs2", .name = "LeftCPUs2",
...@@ -339,7 +334,6 @@ MeterClass RightCPUs2Meter_class = { ...@@ -339,7 +334,6 @@ MeterClass RightCPUs2Meter_class = {
.display = CPUMeter_display .display = CPUMeter_display
}, },
.defaultMode = CUSTOM_METERMODE, .defaultMode = CUSTOM_METERMODE,
.items = 1,
.total = 100.0, .total = 100.0,
.attributes = CPUMeter_attributes, .attributes = CPUMeter_attributes,
.name = "RightCPUs2", .name = "RightCPUs2",
......
...@@ -8,6 +8,8 @@ What's new in version 1.0.3 ...@@ -8,6 +8,8 @@ What's new in version 1.0.3
(thanks to Jann Horn) (thanks to Jann Horn)
* Further performance improvements due to conditional parsing * Further performance improvements due to conditional parsing
of IO data depending on selected fields. 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 What's new in version 1.0.2
......
...@@ -34,7 +34,6 @@ MeterClass ClockMeter_class = { ...@@ -34,7 +34,6 @@ MeterClass ClockMeter_class = {
.setValues = ClockMeter_setValues, .setValues = ClockMeter_setValues,
.defaultMode = TEXT_METERMODE, .defaultMode = TEXT_METERMODE,
.total = 100.0, .total = 100.0,
.items = 1,
.attributes = ClockMeter_attributes, .attributes = ClockMeter_attributes,
.name = "Clock", .name = "Clock",
.uiName = "Clock", .uiName = "Clock",
......
...@@ -32,7 +32,6 @@ MeterClass HostnameMeter_class = { ...@@ -32,7 +32,6 @@ MeterClass HostnameMeter_class = {
.setValues = HostnameMeter_setValues, .setValues = HostnameMeter_setValues,
.defaultMode = TEXT_METERMODE, .defaultMode = TEXT_METERMODE,
.total = 100.0, .total = 100.0,
.items = 1,
.attributes = HostnameMeter_attributes, .attributes = HostnameMeter_attributes,
.name = "Hostname", .name = "Hostname",
.uiName = "Hostname", .uiName = "Hostname",
......
...@@ -74,7 +74,7 @@ MeterClass LoadAverageMeter_class = { ...@@ -74,7 +74,7 @@ MeterClass LoadAverageMeter_class = {
}, },
.setValues = LoadAverageMeter_setValues, .setValues = LoadAverageMeter_setValues,
.defaultMode = TEXT_METERMODE, .defaultMode = TEXT_METERMODE,
.items = 3, .maxItems = 3,
.total = 100.0, .total = 100.0,
.attributes = LoadAverageMeter_attributes, .attributes = LoadAverageMeter_attributes,
.name = "LoadAverage", .name = "LoadAverage",
...@@ -90,7 +90,6 @@ MeterClass LoadMeter_class = { ...@@ -90,7 +90,6 @@ MeterClass LoadMeter_class = {
}, },
.setValues = LoadMeter_setValues, .setValues = LoadMeter_setValues,
.defaultMode = TEXT_METERMODE, .defaultMode = TEXT_METERMODE,
.items = 1,
.total = 100.0, .total = 100.0,
.attributes = LoadMeter_attributes, .attributes = LoadMeter_attributes,
.name = "Load", .name = "Load",
......
...@@ -66,7 +66,7 @@ MeterClass MemoryMeter_class = { ...@@ -66,7 +66,7 @@ MeterClass MemoryMeter_class = {
}, },
.setValues = MemoryMeter_setValues, .setValues = MemoryMeter_setValues,
.defaultMode = BAR_METERMODE, .defaultMode = BAR_METERMODE,
.items = 3, .maxItems = 3,
.total = 100.0, .total = 100.0,
.attributes = MemoryMeter_attributes, .attributes = MemoryMeter_attributes,
"Memory", "Memory",
......
...@@ -52,12 +52,13 @@ typedef struct MeterClass_ { ...@@ -52,12 +52,13 @@ typedef struct MeterClass_ {
const Meter_Draw draw; const Meter_Draw draw;
const Meter_SetValues setValues; const Meter_SetValues setValues;
const int defaultMode; const int defaultMode;
int items;
const double total; const double total;
const int* attributes; const int* attributes;
const char* name; const char* name;
const char* uiName; const char* uiName;
const char* caption; const char* caption;
const char maxItems;
char curItems;
} MeterClass; } MeterClass;
#define As_Meter(this_) ((MeterClass*)((this_)->super.klass)) #define As_Meter(this_) ((MeterClass*)((this_)->super.klass))
...@@ -70,8 +71,8 @@ typedef struct MeterClass_ { ...@@ -70,8 +71,8 @@ typedef struct MeterClass_ {
#define Meter_doneFn(this_) As_Meter(this_)->done #define Meter_doneFn(this_) As_Meter(this_)->done
#define Meter_setValues(this_, c_, i_) As_Meter(this_)->setValues((Meter*)(this_), c_, i_) #define Meter_setValues(this_, c_, i_) As_Meter(this_)->setValues((Meter*)(this_), c_, i_)
#define Meter_defaultMode(this_) As_Meter(this_)->defaultMode #define Meter_defaultMode(this_) As_Meter(this_)->defaultMode
#define Meter_getItems(this_) As_Meter(this_)->items #define Meter_getItems(this_) As_Meter(this_)->curItems
#define Meter_setItems(this_, n_) As_Meter(this_)->items = (n_) #define Meter_setItems(this_, n_) As_Meter(this_)->curItems = (n_)
#define Meter_attributes(this_) As_Meter(this_)->attributes #define Meter_attributes(this_) As_Meter(this_)->attributes
#define Meter_name(this_) As_Meter(this_)->name #define Meter_name(this_) As_Meter(this_)->name
#define Meter_uiName(this_) As_Meter(this_)->uiName #define Meter_uiName(this_) As_Meter(this_)->uiName
...@@ -146,12 +147,17 @@ MeterClass* Meter_types[] = { ...@@ -146,12 +147,17 @@ MeterClass* Meter_types[] = {
}; };
Meter* Meter_new(ProcessList* pl, int param, MeterClass* type) { 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); Object_setClass(this, type);
this->h = 1; this->h = 1;
this->param = param; this->param = param;
this->pl = pl; 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->total = type->total;
this->caption = strdup(type->caption); this->caption = strdup(type->caption);
if (Meter_initFn(this)) if (Meter_initFn(this))
......
...@@ -30,12 +30,13 @@ typedef struct MeterClass_ { ...@@ -30,12 +30,13 @@ typedef struct MeterClass_ {
const Meter_Draw draw; const Meter_Draw draw;
const Meter_SetValues setValues; const Meter_SetValues setValues;
const int defaultMode; const int defaultMode;
int items;
const double total; const double total;
const int* attributes; const int* attributes;
const char* name; const char* name;
const char* uiName; const char* uiName;
const char* caption; const char* caption;
const char maxItems;
char curItems;
} MeterClass; } MeterClass;
#define As_Meter(this_) ((MeterClass*)((this_)->super.klass)) #define As_Meter(this_) ((MeterClass*)((this_)->super.klass))
...@@ -48,8 +49,8 @@ typedef struct MeterClass_ { ...@@ -48,8 +49,8 @@ typedef struct MeterClass_ {
#define Meter_doneFn(this_) As_Meter(this_)->done #define Meter_doneFn(this_) As_Meter(this_)->done
#define Meter_setValues(this_, c_, i_) As_Meter(this_)->setValues((Meter*)(this_), c_, i_) #define Meter_setValues(this_, c_, i_) As_Meter(this_)->setValues((Meter*)(this_), c_, i_)
#define Meter_defaultMode(this_) As_Meter(this_)->defaultMode #define Meter_defaultMode(this_) As_Meter(this_)->defaultMode
#define Meter_getItems(this_) As_Meter(this_)->items #define Meter_getItems(this_) As_Meter(this_)->curItems
#define Meter_setItems(this_, n_) As_Meter(this_)->items = (n_) #define Meter_setItems(this_, n_) As_Meter(this_)->curItems = (n_)
#define Meter_attributes(this_) As_Meter(this_)->attributes #define Meter_attributes(this_) As_Meter(this_)->attributes
#define Meter_name(this_) As_Meter(this_)->name #define Meter_name(this_) As_Meter(this_)->name
#define Meter_uiName(this_) As_Meter(this_)->uiName #define Meter_uiName(this_) As_Meter(this_)->uiName
......
...@@ -66,7 +66,6 @@ MeterClass SwapMeter_class = { ...@@ -66,7 +66,6 @@ MeterClass SwapMeter_class = {
}, },
.setValues = SwapMeter_setValues, .setValues = SwapMeter_setValues,
.defaultMode = BAR_METERMODE, .defaultMode = BAR_METERMODE,
.items = 1,
.total = 100.0, .total = 100.0,
.attributes = SwapMeter_attributes, .attributes = SwapMeter_attributes,
.name = "Swap", .name = "Swap",
......
...@@ -63,7 +63,6 @@ MeterClass TasksMeter_class = { ...@@ -63,7 +63,6 @@ MeterClass TasksMeter_class = {
}, },
.setValues = TasksMeter_setValues, .setValues = TasksMeter_setValues,
.defaultMode = TEXT_METERMODE, .defaultMode = TEXT_METERMODE,
.items = 1,
.total = 100.0, .total = 100.0,
.attributes = TasksMeter_attributes, .attributes = TasksMeter_attributes,
.name = "Tasks", .name = "Tasks",
......
...@@ -56,7 +56,6 @@ MeterClass UptimeMeter_class = { ...@@ -56,7 +56,6 @@ MeterClass UptimeMeter_class = {
}, },
.setValues = UptimeMeter_setValues, .setValues = UptimeMeter_setValues,
.defaultMode = TEXT_METERMODE, .defaultMode = TEXT_METERMODE,
.items = 1,
.total = 100.0, .total = 100.0,
.attributes = UptimeMeter_attributes, .attributes = UptimeMeter_attributes,
.name = "Uptime", .name = "Uptime",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment