From 07667bf7f06976a25d4cb0ba1a333e30b4a94383 Mon Sep 17 00:00:00 2001 From: vanhofen Date: Mon, 6 Feb 2017 21:09:42 +0100 Subject: [PATCH] hdd_menu: fix hd-idle/hdparm logic; fix small memleaks Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/041135986694282b442277f913af2825b917e739 Author: vanhofen Date: 2017-02-06 (Mon, 06 Feb 2017) Origin message was: ------------------ - hdd_menu: fix hd-idle/hdparm logic; fix small memleaks --- src/gui/hdd_menu.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/gui/hdd_menu.cpp b/src/gui/hdd_menu.cpp index 8205ddae9..0f6b1d058 100644 --- a/src/gui/hdd_menu.cpp +++ b/src/gui/hdd_menu.cpp @@ -1113,12 +1113,12 @@ int CHDDDestExec::exec(CMenuTarget* /*parent*/, const std::string&) if (n < 0) return menu_return::RETURN_NONE; - const char hdidle[] = "/sbin/hd-idle"; - bool have_hdidle = !access(hdidle, X_OK); - if (g_settings.hdd_sleep > 0 && g_settings.hdd_sleep < 60) g_settings.hdd_sleep = 60; + const char hdidle[] = "/sbin/hd-idle"; + bool have_hdidle = !access(hdidle, X_OK); + if (have_hdidle) { system("kill $(pidof hd-idle)"); int sleep_seconds = g_settings.hdd_sleep; @@ -1134,12 +1134,22 @@ int CHDDDestExec::exec(CMenuTarget* /*parent*/, const std::string&) } if (sleep_seconds) my_system(3, hdidle, "-i", to_string(sleep_seconds).c_str()); + + while (n--) + free(namelist[i]); + free(namelist); + return menu_return::RETURN_NONE; } const char hdparm[] = "/sbin/hdparm"; bool have_hdparm = !access(hdparm, X_OK); if (!have_hdparm) + { + while (n--) + free(namelist[i]); + free(namelist); return menu_return::RETURN_NONE; + } struct stat stat_buf; bool have_nonbb_hdparm = !::lstat(hdparm, &stat_buf) && !S_ISLNK(stat_buf.st_mode); @@ -1153,12 +1163,11 @@ int CHDDDestExec::exec(CMenuTarget* /*parent*/, const std::string&) snprintf(M_opt, sizeof(M_opt), "-M%d", g_settings.hdd_noise); snprintf(opt, sizeof(opt), "/dev/%s",namelist[i]->d_name); - if (have_hdidle) - my_system(3, hdparm, M_opt, opt); - else if (have_nonbb_hdparm) + if (have_nonbb_hdparm) my_system(4, hdparm, M_opt, S_opt, opt); else // busybox hdparm doesn't support "-M" my_system(3, hdparm, S_opt, opt); + free(namelist[i]); } free(namelist);