Fixed some memory leaks in the paramtree code (discussion #144).
- root_param was never deleted - modified set_format() and set_long_format() to get rid of strdup()
This commit is contained in:
parent
c525d9e5fc
commit
86e4675a1d
@ -926,7 +926,7 @@ void bx_init_options()
|
||||
"", BX_PATHNAME_LEN);
|
||||
sprintf(label, "Name of optional ROM image #%d", i+1);
|
||||
strcat(label, " : %s");
|
||||
path->set_format(strdup(label));
|
||||
path->set_format(label);
|
||||
sprintf(descr, "The address at which the optional ROM image #%d should be loaded", i+1);
|
||||
optaddr = new bx_param_num_c(optnum,
|
||||
"address",
|
||||
@ -938,7 +938,7 @@ void bx_init_options()
|
||||
optaddr->set_format("0x%05x");
|
||||
sprintf(label, "Optional ROM #%d address:", i+1);
|
||||
strcat(label, " 0x%05x");
|
||||
optaddr->set_long_format(strdup(label));
|
||||
optaddr->set_long_format(label);
|
||||
deplist = new bx_list_c(NULL);
|
||||
deplist->add(optaddr);
|
||||
path->set_dependent_list(deplist);
|
||||
@ -958,7 +958,7 @@ void bx_init_options()
|
||||
"", BX_PATHNAME_LEN);
|
||||
sprintf(label, "Name of optional RAM image #%d", i+1);
|
||||
strcat(label, " : %s");
|
||||
path->set_format(strdup(label));
|
||||
path->set_format(label);
|
||||
sprintf(descr, "The address at which the optional RAM image #%d should be loaded", i+1);
|
||||
optaddr = new bx_param_num_c(optnum,
|
||||
"address",
|
||||
@ -970,7 +970,7 @@ void bx_init_options()
|
||||
optaddr->set_format("0x%05x");
|
||||
sprintf(label, "Optional RAM #%d address:", i+1);
|
||||
strcat(label, " 0x%05x");
|
||||
optaddr->set_long_format(strdup(label));
|
||||
optaddr->set_long_format(label);
|
||||
deplist = new bx_list_c(NULL);
|
||||
deplist->add(optaddr);
|
||||
path->set_dependent_list(deplist);
|
||||
|
@ -40,6 +40,8 @@ bx_param_c::bx_param_c(Bit32u id, const char *param_name, const char *param_desc
|
||||
parent(NULL),
|
||||
description(NULL),
|
||||
label(NULL),
|
||||
text_format(NULL),
|
||||
long_text_format(NULL),
|
||||
ask_format(NULL),
|
||||
group_name(NULL)
|
||||
{
|
||||
@ -47,8 +49,8 @@ bx_param_c::bx_param_c(Bit32u id, const char *param_name, const char *param_desc
|
||||
this->name = new char[strlen(param_name)+1];
|
||||
strcpy(this->name, param_name);
|
||||
set_description(param_desc);
|
||||
this->text_format = default_text_format;
|
||||
this->long_text_format = default_text_format;
|
||||
set_format(default_text_format);
|
||||
set_long_format(default_text_format);
|
||||
this->runtime_param = 0;
|
||||
this->enabled = 1;
|
||||
this->options = 0;
|
||||
@ -62,6 +64,8 @@ bx_param_c::bx_param_c(Bit32u id, const char *param_name, const char *param_labe
|
||||
parent(NULL),
|
||||
description(NULL),
|
||||
label(NULL),
|
||||
text_format(NULL),
|
||||
long_text_format(NULL),
|
||||
ask_format(NULL),
|
||||
group_name(NULL)
|
||||
{
|
||||
@ -70,8 +74,8 @@ bx_param_c::bx_param_c(Bit32u id, const char *param_name, const char *param_labe
|
||||
strcpy(this->name, param_name);
|
||||
set_description(param_desc);
|
||||
set_label(param_label);
|
||||
this->text_format = default_text_format;
|
||||
this->long_text_format = default_text_format;
|
||||
set_format(default_text_format);
|
||||
set_long_format(default_text_format);
|
||||
this->runtime_param = 0;
|
||||
this->enabled = 1;
|
||||
this->options = 0;
|
||||
@ -85,6 +89,8 @@ bx_param_c::~bx_param_c()
|
||||
delete [] name;
|
||||
delete [] label;
|
||||
delete [] description;
|
||||
delete [] text_format;
|
||||
delete [] long_text_format;
|
||||
delete [] ask_format;
|
||||
delete [] group_name;
|
||||
delete dependent_list;
|
||||
@ -112,6 +118,28 @@ void bx_param_c::set_label(const char *text)
|
||||
}
|
||||
}
|
||||
|
||||
void bx_param_c::set_format(const char *format)
|
||||
{
|
||||
delete [] text_format;
|
||||
if (format) {
|
||||
text_format = new char[strlen(format)+1];
|
||||
strcpy(text_format, format);
|
||||
} else {
|
||||
text_format = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void bx_param_c::set_long_format(const char *format)
|
||||
{
|
||||
delete [] long_text_format;
|
||||
if (format) {
|
||||
long_text_format = new char[strlen(format)+1];
|
||||
strcpy(long_text_format, format);
|
||||
} else {
|
||||
long_text_format = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void bx_param_c::set_ask_format(const char *format)
|
||||
{
|
||||
delete [] ask_format;
|
||||
@ -371,7 +399,7 @@ bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
|
||||
val.p64bit = ptr_to_real_val;
|
||||
if (base == BASE_HEX) {
|
||||
this->base = base;
|
||||
this->text_format = "0x" FMT_LL "x";
|
||||
set_format("0x" FMT_LL "x");
|
||||
}
|
||||
}
|
||||
|
||||
@ -390,7 +418,7 @@ bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
|
||||
val.p64bit = (Bit64s*) ptr_to_real_val;
|
||||
if (base == BASE_HEX) {
|
||||
this->base = base;
|
||||
this->text_format = "0x" FMT_LL "x";
|
||||
set_format("0x" FMT_LL "x");
|
||||
}
|
||||
}
|
||||
|
||||
@ -409,7 +437,7 @@ bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
|
||||
val.p32bit = ptr_to_real_val;
|
||||
if (base == BASE_HEX) {
|
||||
this->base = base;
|
||||
this->text_format = "0x%08x";
|
||||
set_format("0x%08x");
|
||||
}
|
||||
}
|
||||
|
||||
@ -428,7 +456,7 @@ bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
|
||||
val.p32bit = (Bit32s*) ptr_to_real_val;
|
||||
if (base == BASE_HEX) {
|
||||
this->base = base;
|
||||
this->text_format = "0x%08x";
|
||||
set_format("0x%08x");
|
||||
}
|
||||
}
|
||||
|
||||
@ -447,7 +475,7 @@ bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
|
||||
val.p16bit = ptr_to_real_val;
|
||||
if (base == BASE_HEX) {
|
||||
this->base = base;
|
||||
this->text_format = "0x%04x";
|
||||
set_format("0x%04x");
|
||||
}
|
||||
}
|
||||
|
||||
@ -466,7 +494,7 @@ bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
|
||||
val.p16bit = (Bit16s*) ptr_to_real_val;
|
||||
if (base == BASE_HEX) {
|
||||
this->base = base;
|
||||
this->text_format = "0x%04x";
|
||||
set_format("0x%04x");
|
||||
}
|
||||
}
|
||||
|
||||
@ -486,7 +514,7 @@ bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
|
||||
val.p8bit = ptr_to_real_val;
|
||||
if (base == BASE_HEX) {
|
||||
this->base = base;
|
||||
this->text_format = "0x%02x";
|
||||
set_format("0x%02x");
|
||||
}
|
||||
}
|
||||
|
||||
@ -505,7 +533,7 @@ bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
|
||||
val.p8bit = (Bit8s*) ptr_to_real_val;
|
||||
if (base == BASE_HEX) {
|
||||
this->base = base;
|
||||
this->text_format = "0x%02x";
|
||||
set_format("0x%02x");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,11 +99,11 @@ protected:
|
||||
bx_list_c *parent;
|
||||
char *name;
|
||||
char *description;
|
||||
char *label; // label string for text menus and gui dialogs
|
||||
const char *text_format; // printf format string. %d for ints, %s for strings, etc.
|
||||
const char *long_text_format; // printf format string. %d for ints, %s for strings, etc.
|
||||
char *ask_format; // format string for asking for a new value
|
||||
char *group_name; // name of the group the param belongs to
|
||||
char *label; // label string for text menus and gui dialogs
|
||||
char *text_format; // printf format string. %d for ints, %s for strings, etc.
|
||||
char *long_text_format; // printf format string. %d for ints, %s for strings, etc.
|
||||
char *ask_format; // format string for asking for a new value
|
||||
char *group_name; // name of the group the param belongs to
|
||||
bool runtime_param;
|
||||
bool enabled;
|
||||
Bit32u options;
|
||||
@ -131,10 +131,10 @@ public:
|
||||
|
||||
int get_param_path(char *path_out, int maxlen);
|
||||
|
||||
void set_format(const char *format) {text_format = format;}
|
||||
void set_format(const char *format);
|
||||
const char *get_format() const {return text_format;}
|
||||
|
||||
void set_long_format(const char *format) {long_text_format = format;}
|
||||
void set_long_format(const char *format);
|
||||
const char *get_long_format() const {return long_text_format;}
|
||||
|
||||
void set_ask_format(const char *format);
|
||||
|
@ -365,6 +365,7 @@ void bx_cleanup_siminterface()
|
||||
}
|
||||
if (root_param) {
|
||||
root_param->clear();
|
||||
delete root_param;
|
||||
root_param = NULL;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user