diff --git a/res/stasis/control.c b/res/stasis/control.c index 99407dfab33876a6d4c8562d4a4558d63ea6da36..bae64ecc241b891df59f143e31dc747e13cfbbc0 100644 --- a/res/stasis/control.c +++ b/res/stasis/control.c @@ -746,6 +746,14 @@ static int app_send_command_on_condition(struct stasis_app_control *control, RAII_VAR(struct stasis_app_command *, command, NULL, ao2_cleanup); if (control == NULL || control->is_done) { + /* If exec_command_on_condition fails, it calls the data_destructor. + * In order to provide consistent behavior, we'll also call the data_destructor + * on this error path. This way, callers never have to call the + * data_destructor themselves. + */ + if (data_destructor) { + data_destructor(data); + } return -1; } @@ -771,6 +779,14 @@ int stasis_app_send_command_async(struct stasis_app_control *control, RAII_VAR(struct stasis_app_command *, command, NULL, ao2_cleanup); if (control == NULL || control->is_done) { + /* If exec_command fails, it calls the data_destructor. In order to + * provide consistent behavior, we'll also call the data_destructor + * on this error path. This way, callers never have to call the + * data_destructor themselves. + */ + if (data_destructor) { + data_destructor(data); + } return -1; }