Skip to content

Commit f122044

Browse files
committed
osc: Do some minimal cleanup of mem allocated for dev & chn
in osc.c, each struct iio_device and iio_channel get assigned some dynamically allocated memory which never gets freed. Signed-off-by: Dan Nechita <[email protected]>
1 parent cdc7209 commit f122044

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

osc.c

+30
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static int load_profile(const char *filename, bool load_plugins);
7070
static int capture_setup(void);
7171
static void capture_start(void);
7272
static void stop_sampling(void);
73+
static void cleanup_device_list(struct iio_context *_ctx);
7374

7475
static char * dma_devices[] = {
7576
"ad9122",
@@ -1759,6 +1760,8 @@ static void do_quit(bool reload)
17591760
g_list_free(plot_list);
17601761
free_setup_check_fct_list();
17611762
osc_plot_reset_numbering();
1763+
if (ctx)
1764+
cleanup_device_list(ctx);
17621765

17631766
if (!reload && gtk_main_level())
17641767
gtk_main_quit();
@@ -1873,6 +1876,33 @@ static void init_device_list(struct iio_context *_ctx)
18731876
}
18741877
}
18751878

1879+
static void cleanup_device_list(struct iio_context *_ctx)
1880+
{
1881+
unsigned int d, c, nb_channels;
1882+
struct iio_device *dev;
1883+
struct iio_channel *chn;
1884+
struct extra_dev_info *dev_info;
1885+
struct extra_info *chn_info;
1886+
1887+
for (d = 0; d < num_devices; d++) {
1888+
dev = iio_context_get_device(_ctx, d);
1889+
nb_channels = iio_device_get_channels_count(dev);
1890+
1891+
for (c = 0; c < nb_channels; c++) {
1892+
chn = iio_device_get_channel(dev, c);
1893+
chn_info = iio_channel_get_data(chn);
1894+
if (chn_info) {
1895+
free(chn_info);
1896+
iio_channel_set_data(chn, NULL);
1897+
}
1898+
}
1899+
1900+
dev_info = iio_device_get_data(dev);
1901+
free(dev_info);
1902+
iio_device_set_data(dev, NULL);
1903+
}
1904+
}
1905+
18761906
#define ENTER_KEY_CODE 0xFF0D
18771907

18781908
gboolean save_sample_count_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)

0 commit comments

Comments
 (0)