Commit 4d8d02a1 authored by Marcus Nordenberg's avatar Marcus Nordenberg

profinet configurator: fix some memory leaks and other memory issues

parent ed36bc73
This diff is collapsed.
...@@ -282,7 +282,10 @@ void GsdmlAttr::activate_cmd_ca() ...@@ -282,7 +282,10 @@ void GsdmlAttr::activate_cmd_ca()
} }
} }
GsdmlAttr::~GsdmlAttr() {} GsdmlAttr::~GsdmlAttr() {
if (wow)
delete wow;
}
GsdmlAttr::GsdmlAttr(void* a_parent_ctx, void* a_object, pn_gsdml* a_gsdml, GsdmlAttr::GsdmlAttr(void* a_parent_ctx, void* a_object, pn_gsdml* a_gsdml,
int a_edit_mode, const char* a_data_filename) int a_edit_mode, const char* a_data_filename)
......
...@@ -1471,13 +1471,21 @@ int GsdmlAttrNav::save(const char* filename) ...@@ -1471,13 +1471,21 @@ int GsdmlAttrNav::save(const char* filename)
(char*)gsdml->ApplicationProcess->ChannelDiagList->ChannelDiagItem[i] (char*)gsdml->ApplicationProcess->ChannelDiagList->ChannelDiagItem[i]
->Body.Name.p, ->Body.Name.p,
sizeof(cd->name)); sizeof(cd->name));
//Make sure we null terminate these in case our buffer is too small to accomodate the entire diag name string.
cd->name[sizeof(cd->name) - 1] = '\0';
if (gsdml->ApplicationProcess->ChannelDiagList->ChannelDiagItem[i] if (gsdml->ApplicationProcess->ChannelDiagList->ChannelDiagItem[i]
->Body.Help.p) ->Body.Help.p)
strncpy(cd->help, {
(char*)gsdml->ApplicationProcess->ChannelDiagList strncpy(cd->help,
->ChannelDiagItem[i] (char*)gsdml->ApplicationProcess->ChannelDiagList
->Body.Help.p, ->ChannelDiagItem[i]
sizeof(cd->help)); ->Body.Help.p,
sizeof(cd->help));
//Make sure we null terminate these in case our buffer is too small to accomodate the entire help string.
cd->help[sizeof(cd->help) - 1] = '\0';
}
dev_data.channel_diag.push_back(cd); dev_data.channel_diag.push_back(cd);
} }
} }
......
...@@ -62,8 +62,8 @@ GsdmlSlotData* GsdmlDeviceData::paste_slotdata = 0; ...@@ -62,8 +62,8 @@ GsdmlSlotData* GsdmlDeviceData::paste_slotdata = 0;
GsdmlChannelDiag::GsdmlChannelDiag() : error_type(0) GsdmlChannelDiag::GsdmlChannelDiag() : error_type(0)
{ {
strcpy(name, ""); memset(name, 0, sizeof(name));
strcpy(help, ""); memset(help, 0, sizeof(help));
} }
int GsdmlChannelDiag::print(std::ofstream& fp) int GsdmlChannelDiag::print(std::ofstream& fp)
...@@ -89,9 +89,18 @@ GsdmlDataRecord::GsdmlDataRecord(const GsdmlDataRecord& x) ...@@ -89,9 +89,18 @@ GsdmlDataRecord::GsdmlDataRecord(const GsdmlDataRecord& x)
int GsdmlDataRecord::print(std::ofstream& fp, bool reverse_endianess) int GsdmlDataRecord::print(std::ofstream& fp, bool reverse_endianess)
{ {
char str[1024]; char str[1024];
unsigned char* data;
unsigned char* data = // If we have allocated memory for reversed endianess we come from the pn configurator otherwise we use the data as is.
(reverse_endianess ? this->data_reversed_endianess : this->data); // The method SetIoDeviceData for instance reads the raw data and then recreates the pn configuration file.
if (data_reversed_endianess)
{
data = (reverse_endianess ? this->data_reversed_endianess : this->data);
}
else
{
data = this->data;
}
co_xml_parser::data_to_ostring(data, data_length, str, sizeof(str)); co_xml_parser::data_to_ostring(data, data_length, str, sizeof(str));
......
...@@ -63,6 +63,8 @@ public: ...@@ -63,6 +63,8 @@ public:
{ {
if (data) if (data)
free(data); free(data);
if (data_reversed_endianess)
free(data_reversed_endianess);
} }
GsdmlDataRecord(const GsdmlDataRecord& x); GsdmlDataRecord(const GsdmlDataRecord& x);
...@@ -170,7 +172,7 @@ public: ...@@ -170,7 +172,7 @@ public:
GsdmlChannelDiag(); GsdmlChannelDiag();
unsigned short error_type; unsigned short error_type;
char name[200]; char name[200];
char help[256]; char help[4096]; // We need a large buffer for most of the help text in the diagnostics...
int print(std::ofstream& fp); int print(std::ofstream& fp);
}; };
...@@ -208,7 +210,10 @@ public: ...@@ -208,7 +210,10 @@ public:
static GsdmlSlotData* paste_slotdata; static GsdmlSlotData* paste_slotdata;
std::vector<GsdmlChannelDiag*> channel_diag; std::vector<GsdmlChannelDiag*> channel_diag;
~GsdmlDeviceData() { device_reset(); } ~GsdmlDeviceData() {
device_reset();
channel_diag_reset();
}
void device_reset() void device_reset()
{ {
for (unsigned int i = 0; i < slot_data.size(); i++) for (unsigned int i = 0; i < slot_data.size(); i++)
......
...@@ -229,7 +229,10 @@ static pwr_tStatus GetIoDeviceData(pwr_tAttrRef Object, const char* Attr, ...@@ -229,7 +229,10 @@ static pwr_tStatus GetIoDeviceData(pwr_tAttrRef Object, const char* Attr,
GsdmlDeviceData* data = new GsdmlDeviceData(); GsdmlDeviceData* data = new GsdmlDeviceData();
sts = data->read(datafile); sts = data->read(datafile);
if (EVEN(sts)) if (EVEN(sts))
{
delete data;
return sts; return sts;
}
sts = data->get_value(Attr, Buf, BufSize); sts = data->get_value(Attr, Buf, BufSize);
...@@ -250,7 +253,10 @@ static pwr_tStatus SetIoDeviceData(pwr_tAttrRef Object, const char* Attr, ...@@ -250,7 +253,10 @@ static pwr_tStatus SetIoDeviceData(pwr_tAttrRef Object, const char* Attr,
GsdmlDeviceData* data = new GsdmlDeviceData(); GsdmlDeviceData* data = new GsdmlDeviceData();
sts = data->read(datafile); sts = data->read(datafile);
if (EVEN(sts)) if (EVEN(sts))
{
delete data;
return sts; return sts;
}
sts = data->modify_value(Attr, Value); sts = data->modify_value(Attr, Value);
if (ODD(sts)) if (ODD(sts))
......
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