From e8f1723f73cac383fc46c6c8153c038913d1a906 Mon Sep 17 00:00:00 2001 From: Nick Kelsey Date: Wed, 24 Aug 2016 16:36:07 -0700 Subject: [PATCH] fix possible memory leak when out of memory. --- hdhomerun_device_selector.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hdhomerun_device_selector.c b/hdhomerun_device_selector.c index e75882c..43cf065 100644 --- a/hdhomerun_device_selector.c +++ b/hdhomerun_device_selector.c @@ -71,12 +71,13 @@ void hdhomerun_device_selector_add_device(struct hdhomerun_device_selector_t *hd } } - hds->hd_list = (struct hdhomerun_device_t **)realloc(hds->hd_list, (hds->hd_count + 1) * sizeof(struct hdhomerun_device_selector_t *)); - if (!hds->hd_list) { + struct hdhomerun_device_t **hd_list = (struct hdhomerun_device_t **)realloc(hds->hd_list, (hds->hd_count + 1) * sizeof(struct hdhomerun_device_selector_t *)); + if (!hd_list) { hdhomerun_debug_printf(hds->dbg, "hdhomerun_device_selector_add_device: failed to allocate device list\n"); return; } + hds->hd_list = hd_list; hds->hd_list[hds->hd_count++] = hd; } @@ -322,7 +323,7 @@ static bool_t hdhomerun_device_selector_choose_test(struct hdhomerun_device_sele /* * Attempt to aquire lock. */ - char *error; + char *error = NULL; int ret = hdhomerun_device_tuner_lockkey_request(test_hd, &error); if (ret > 0) { hdhomerun_debug_printf(hds->dbg, "hdhomerun_device_selector_choose_test: device %s chosen\n", name);