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

sipo
Ondřej Hruška 6 years ago
parent 69fa263f45
commit b5d9d146f9
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 1
      framework/resources.c
  2. 9
      framework/unit_registry.c
  3. 3
      platform/pin_utils.c

@ -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++) {

@ -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;

@ -263,8 +263,9 @@ uint16_t port_pack(uint16_t spread, uint16_t mask)
void deinit_unit_pins(Unit *unit)
{
for (uint32_t rsc = R_PA0; rsc <= R_PF0; rsc++) {
for (uint32_t rsc = R_PA0; rsc <= R_PF15; rsc++) {
if (RSC_IS_HELD(unit->resources, rsc)) {
dbg("Freeing pin %s", rsc_get_name((Resource)rsc));
GPIO_TypeDef *port = port_periphs[(rsc-R_PA0) / 16];
uint32_t ll_pin = ll_pins[(rsc-R_PA0)%16];
LL_GPIO_SetPinMode(port, ll_pin, LL_GPIO_MODE_ANALOG);

Loading…
Cancel
Save