Skip to content

Commit

Permalink
Fix event callback on shutdown (closes #2869)
Browse files Browse the repository at this point in the history
  • Loading branch information
zuckschwerdt committed Mar 11, 2024
1 parent ce30ff8 commit a8fe08c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/r_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,11 @@ void r_free_cfg(r_cfg_t *cfg)
if (cfg->dev) {
sdr_deactivate(cfg->dev);
sdr_close(cfg->dev);
cfg->dev = NULL;
}

free(cfg->gain_str);
cfg->gain_str = NULL;

for (void **iter = cfg->demod->dumper.elems; iter && *iter; ++iter) {
file_info_t const *dumper = *iter;
Expand All @@ -224,8 +226,10 @@ void r_free_cfg(r_cfg_t *cfg)

if (cfg->demod->am_analyze)
am_analyze_free(cfg->demod->am_analyze);
cfg->demod->am_analyze = NULL;

pulse_detect_free(cfg->demod->pulse_detect);
cfg->demod->pulse_detect = NULL;

list_free_elems(&cfg->raw_handler, (list_elem_free_fn)raw_output_free);

Expand All @@ -238,11 +242,14 @@ void r_free_cfg(r_cfg_t *cfg)
list_free_elems(&cfg->in_files, NULL);

free(cfg->demod);
cfg->demod = NULL;

free(cfg->devices);
cfg->devices = NULL;

mg_mgr_free(cfg->mgr);
free(cfg->mgr);
cfg->mgr = NULL;

//free(cfg);
}
Expand Down
13 changes: 13 additions & 0 deletions src/rtl_433.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ static void sdr_callback(unsigned char *iq_buf, uint32_t len, void *ctx)
char time_str[LOCAL_TIME_BUFLEN];
unsigned long n_samples;

if (!demod) {
// might happen when the demod closed and we get a last data frame
return; // ignore the data
}

// do this here and not in sdr_handler so realtime replay can use rtl_tcp output
for (void **iter = cfg->raw_handler.elems; iter && *iter; ++iter) {
raw_output_t *output = *iter;
Expand Down Expand Up @@ -1367,6 +1372,7 @@ static void sighandler(int signum)
}
#endif

// NOTE: this handler might be called while already in `r_free_cfg()`.
static void sdr_handler(struct mg_connection *nc, int ev_type, void *ev_data)
{
//fprintf(stderr, "%s: %d, %d, %p, %p\n", __func__, nc->sock, ev_type, nc->user_data, ev_data);
Expand Down Expand Up @@ -1441,6 +1447,13 @@ static void acquire_callback(sdr_event_t *ev, void *ctx)
static int start_sdr(r_cfg_t *cfg)
{
int r;
if (cfg->dev) {
r = sdr_close(cfg->dev);
cfg->dev = NULL;
if (r < 0) {
print_logf(LOG_ERROR, "Input", "Closing SDR failed (%d)", r);
}
}
r = sdr_open(&cfg->dev, cfg->dev_query, cfg->verbosity);
if (r < 0) {
return -1; // exit(2);
Expand Down

0 comments on commit a8fe08c

Please sign in to comment.