Skip to content

Commit

Permalink
iio-monitor: Fix memory leaks
Browse files Browse the repository at this point in the history
 * char2Chtype() allocates memory which needs to be freed with freeChtype().
 * getString() allocates memory which needs to be freed with freeChar().

Signed-off-by: Lars-Peter Clausen <[email protected]>
  • Loading branch information
larsclausen committed Feb 19, 2016
1 parent d59cd3d commit dba8a15
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions examples/iio-monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ static void * read_thd(void *d)
RED, name, RED);
str = char2Chtype(buf, &len, &align);
writeChtype(right, 2, line, str, HORIZONTAL, 0, len);
freeChtype(str);
line += 2;

nb_channels = iio_device_get_channels_count(dev);
Expand All @@ -131,13 +132,15 @@ static void * read_thd(void *d)
str = char2Chtype(buf, &len, &align);
writeChtype(right, 2, line, str,
HORIZONTAL, 0, len);
freeChtype(str);

sprintf(buf, "</%u></B>%.3lf %s<!B><!%u>",
YELLOW, get_channel_value(chn),
is_temp ? "°C" : "V", YELLOW);
str = char2Chtype(buf, &len, &align);
writeChtype(right, col / 2, line++,
str, HORIZONTAL, 0, len);
freeChtype(str);
}

if (nb == 0) {
Expand Down Expand Up @@ -193,6 +196,7 @@ int main()
"Please enter the IP or hostname of the server",
"Hostname: ", "localhost");
ctx = iio_create_network_context(hostname);
freeChar(hostname);
if (!ctx)
goto err_destroy_cdk;
}
Expand Down

0 comments on commit dba8a15

Please sign in to comment.