fix: leaks and crash for relay PUT
This commit is contained in:
parent
71f7447f09
commit
77975299a5
3 changed files with 24 additions and 11 deletions
|
@ -84,6 +84,8 @@ controllers::put_relays_one_by_id_and_num(const HttpRequestPtr &req,
|
|||
strncpy(relay->active_schedule_id, body["active_schedule"].asCString(), 32);
|
||||
strncpy(relay->controller_id, controller_id.c_str(), 32);
|
||||
|
||||
relay->reload_active_schedule();
|
||||
|
||||
db_action_result = relay->insert();
|
||||
}
|
||||
|
||||
|
|
|
@ -82,18 +82,9 @@ relay_db_select(sqlite3_stmt *stmt)
|
|||
if (s == SQLITE_ROW)
|
||||
{
|
||||
relay_dbo *new_relay = relay_db_select_mapper(stmt);
|
||||
schedule_dbo **schedules = schedule_dbo::get_by_simple("id", new_relay->active_schedule_id, (intptr_t)&sqlite3_bind_text);
|
||||
|
||||
if(!schedules[0])
|
||||
{
|
||||
free(schedules);
|
||||
schedules = schedule_dbo::get_by_simple("id", "off", (intptr_t)&sqlite3_bind_text);
|
||||
strcpy(new_relay->active_schedule_id, "off");
|
||||
}
|
||||
new_relay->reload_active_schedule();
|
||||
|
||||
new_relay->active_schedule = schedules[0];
|
||||
|
||||
free(schedules);
|
||||
row++;
|
||||
|
||||
all_relays = (relay_dbo**)realloc(all_relays, sizeof(relay_dbo*) * (row + 1));
|
||||
|
@ -119,6 +110,23 @@ relay_db_select(sqlite3_stmt *stmt)
|
|||
return all_relays;
|
||||
}
|
||||
|
||||
void
|
||||
relay_dbo::reload_active_schedule()
|
||||
{
|
||||
schedule_dbo **schedules = schedule_dbo::get_by_simple("id", this->active_schedule_id, (intptr_t)&sqlite3_bind_text);
|
||||
|
||||
if(!schedules[0])
|
||||
{
|
||||
free(schedules);
|
||||
schedules = schedule_dbo::get_by_simple("id", "off", (intptr_t)&sqlite3_bind_text);
|
||||
strcpy(this->active_schedule_id, "off");
|
||||
}
|
||||
|
||||
this->active_schedule = schedules[0];
|
||||
|
||||
free(schedules);
|
||||
}
|
||||
|
||||
bool
|
||||
relay_dbo::update()
|
||||
{
|
||||
|
@ -244,7 +252,7 @@ relay_dbo::free_list(relay_dbo **relays_list)
|
|||
{
|
||||
for(int i = 0; relays_list[i] != nullptr; i++)
|
||||
{
|
||||
free(relays_list[i]);
|
||||
delete relays_list[i];
|
||||
}
|
||||
free(relays_list);
|
||||
}
|
|
@ -18,6 +18,9 @@ public:
|
|||
char active_schedule_id[33];
|
||||
schedule_dbo *active_schedule;
|
||||
|
||||
void
|
||||
reload_active_schedule();
|
||||
|
||||
bool
|
||||
update();
|
||||
|
||||
|
|
Loading…
Reference in a new issue