Bugfix: Discovered memory leak.
--- a/master/canopen.c Wed Apr 05 11:44:41 2006 +0000
+++ b/master/canopen.c Wed Apr 05 11:46:13 2006 +0000
@@ -415,7 +415,7 @@
EC_READ_U16(data + 6) != sdo->index || // SDO index
EC_READ_U8(data + 8) != i) { // SDO subindex
EC_ERR("Invalid entry description response at slave %i while"
- " fetching SDO 0x%04X:%i!\n", slave->ring_position,
+ " fetching SDO entry 0x%04X:%i!\n", slave->ring_position,
sdo->index, i);
ec_print_data(data, rec_size);
return -1;
@@ -434,21 +434,19 @@
if (!(entry = (ec_sdo_entry_t *)
kmalloc(sizeof(ec_sdo_entry_t) + data_size + 1, GFP_KERNEL))) {
- EC_ERR("Failed to allocate entry memory!\n");
+ EC_ERR("Failed to allocate entry!\n");
return -1;
}
entry->subindex = i;
entry->data_type = EC_READ_U16(data + 10);
entry->bit_length = EC_READ_U16(data + 12);
- if (!data_size) {
- entry->name = NULL;
- }
- else {
- entry->name = (uint8_t *) entry + sizeof(ec_sdo_entry_t);
- memcpy(entry->name, data + 16, data_size);
- entry->name[data_size] = 0;
- }
+
+ // memory for name string appended to entry
+ entry->name = (uint8_t *) entry + sizeof(ec_sdo_entry_t);
+
+ memcpy(entry->name, data + 16, data_size);
+ entry->name[data_size] = 0;
list_add_tail(&entry->list, &sdo->entries);
}
--- a/master/master.c Wed Apr 05 11:44:41 2006 +0000
+++ b/master/master.c Wed Apr 05 11:46:13 2006 +0000
@@ -86,9 +86,8 @@
// Alle Slaves entfernen
if (master->slaves) {
- for (i = 0; i < master->slave_count; i++) {
+ for (i = 0; i < master->slave_count; i++)
ec_slave_clear(master->slaves + i);
- }
kfree(master->slaves);
master->slaves = NULL;
}
@@ -108,7 +107,7 @@
}
// EOE-Liste leeren
- list_for_each_entry_safe(eoe, next_eoe, &master->domains, list) {
+ list_for_each_entry_safe(eoe, next_eoe, &master->eoe_slaves, list) {
list_del(&eoe->list);
ec_eoe_clear(eoe);
kfree(eoe);
@@ -411,10 +410,9 @@
if (!master->slave_count) return 0;
- if (!(master->slaves = (ec_slave_t *) kmalloc(master->slave_count
- * sizeof(ec_slave_t),
- GFP_KERNEL))) {
- EC_ERR("Could not allocate memory for slaves!\n");
+ if (!(master->slaves = (ec_slave_t *)
+ kmalloc(master->slave_count * sizeof(ec_slave_t), GFP_KERNEL))) {
+ EC_ERR("Failed to allocate slaves!\n");
return -1;
}
@@ -426,9 +424,8 @@
slave->station_address = i + 1;
}
- // For every slave in the list
- for (i = 0; i < master->slave_count; i++)
- {
+ // For every slave on the bus
+ for (i = 0; i < master->slave_count; i++) {
slave = master->slaves + i;
// Write station address
@@ -461,8 +458,8 @@
// Does the slave support EoE?
if (slave->sii_mailbox_protocols & EC_MBOX_EOE) {
- if (!(eoe = kmalloc(sizeof(ec_eoe_t), GFP_KERNEL))) {
- EC_ERR("Failed to allocate memory for EoE-Object.\n");
+ if (!(eoe = (ec_eoe_t *) kmalloc(sizeof(ec_eoe_t), GFP_KERNEL))) {
+ EC_ERR("Failed to allocate EoE-Object.\n");
return -1;
}
--- a/master/module.c Wed Apr 05 11:44:41 2006 +0000
+++ b/master/module.c Wed Apr 05 11:46:13 2006 +0000
@@ -176,7 +176,7 @@
if (!(master->device = (ec_device_t *)
kmalloc(sizeof(ec_device_t), GFP_KERNEL))) {
- EC_ERR("Failed allocating device!\n");
+ EC_ERR("Failed to allocate device!\n");
return NULL;
}
--- a/master/slave.c Wed Apr 05 11:44:41 2006 +0000
+++ b/master/slave.c Wed Apr 05 11:46:13 2006 +0000
@@ -126,6 +126,7 @@
list_for_each_entry_safe(sdo, next_sdo, &slave->sdo_dictionary, list) {
list_del(&sdo->list);
if (sdo->name) kfree(sdo->name);
+
// Alle Entries freigeben
list_for_each_entry_safe(en, next_en, &sdo->entries, list) {
list_del(&en->list);
@@ -541,6 +542,7 @@
return -1;
}
string->size = size;
+ // string memory appended to string structure
string->data = (char *) string + sizeof(ec_eeprom_string_t);
memcpy(string->data, data + offset + 1, size);
string->data[size] = 0x00;