Skip to content

Commit

Permalink
Fix memory leak in unit conversion (#122)
Browse files Browse the repository at this point in the history
* Set memory debug flag.

* Fix memory leak converting inches to mm.

* Remove memory debug flag.

* Remove memory debug flag.
  • Loading branch information
ianmtaylor1 authored Dec 17, 2023
1 parent be71d74 commit b5428d2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/rtl_433/r_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,12 @@ void data_acquired_handler(r_device* r_dev, data_t* data) {
else if ((d->type == DATA_DOUBLE) &&
(str_endswith(d->key, "_in") || str_endswith(d->key, "_inch"))) {
d->value.v_dbl = inch2mm(d->value.v_dbl);
char* new_label =
str_replace(str_replace(d->key, "_inch", "_in"), "_in", "_mm");
// need to free ptr returned from str_replace
char* new_label1 = str_replace(d->key, "_inch", "_in");
char* new_label2 = str_replace(new_label1, "_in", "_mm");
free(new_label1);
free(d->key);
d->key = new_label;
d->key = new_label2;
char* new_format_label = str_replace(d->format, "in", "mm");
free(d->format);
d->format = new_format_label;
Expand Down

0 comments on commit b5428d2

Please sign in to comment.