fixed the bug with botched deinig, caused by use of malloc instead of calloc

This commit is contained in:
2018-01-07 00:43:42 +01:00
parent 69fa263f45
commit b5d9d146f9
3 changed files with 9 additions and 4 deletions
+1
View File
@@ -211,6 +211,7 @@ void rsc_teardown(Unit *unit)
assert_param(rsc_initialized);
assert_param(unit != NULL);
dbg("Tearing down unit %s", unit->name);
deinit_unit_pins(unit);
for (uint32_t i = 0; i < RSCMAP_LEN; i++) {
+6 -3
View File
@@ -42,6 +42,7 @@ static int32_t unit_count = -1;
void ureg_add_type(const UnitDriver *driver)
{
bool suc = true;
assert_param(driver != NULL);
assert_param(driver->name != NULL);
@@ -57,7 +58,9 @@ void ureg_add_type(const UnitDriver *driver)
assert_param(driver->deInit != NULL);
assert_param(driver->handleRequest != NULL);
UregEntry *re = malloc_s(sizeof(UregEntry));
UregEntry *re = calloc_ck(1, sizeof(UregEntry), &suc);
assert_param(suc);
re->driver = driver;
re->next = NULL;
@@ -108,7 +111,7 @@ Unit *ureg_instantiate(const char *driver_name)
while (re != NULL) {
if (streq(re->driver->name, driver_name)) {
// Create new list entry
UlistEntry *le = malloc_ck(sizeof(UlistEntry), &suc);
UlistEntry *le = calloc_ck(1, sizeof(UlistEntry), &suc);
CHECK_SUC();
le->next = NULL;
@@ -512,7 +515,7 @@ void ureg_report_active_units(TF_ID frame_id)
msglen += count; // one byte per message for the callsign
bool suc = true;
uint8_t *buff = malloc_ck(msglen, &suc);
uint8_t *buff = calloc_ck(1, msglen, &suc);
if (!suc) {
com_respond_error(frame_id, E_OUT_OF_MEM);
return;