Fixes some resource leaks detected by valgrind and coverity scan.
diff --git a/src/devices/ahci.cpp b/src/devices/ahci.cpp index ac06460..7f704b6 100644 --- a/src/devices/ahci.cpp +++ b/src/devices/ahci.cpp @@ -64,8 +64,10 @@ static string disk_name(char *path, char *target, char *shortname) sprintf(line, "%s/%s/model", pathname, dirent->d_name); file = fopen(line, "r"); if (file) { - if (fgets(line, 4096, file) == NULL) + if (fgets(line, 4096, file) == NULL) { + fclose(file); break; + } fclose(file); c = strchr(line, '\n'); if (c) diff --git a/src/devices/devfreq.cpp b/src/devices/devfreq.cpp index e16951c..23c4b0c 100644 --- a/src/devices/devfreq.cpp +++ b/src/devices/devfreq.cpp @@ -238,6 +238,7 @@ void create_all_devfreq_devices(void)
callback fn = &devfreq_dev_callback; process_directory(p.c_str(), fn); + closedir(dir); }
void initialize_devfreq(void) diff --git a/src/perf/perf_bundle.cpp b/src/perf/perf_bundle.cpp index b0e982b..cf1ae11 100644 --- a/src/perf/perf_bundle.cpp +++ b/src/perf/perf_bundle.cpp @@ -142,8 +142,10 @@ static void parse_event_format(const char *event_name)
buf = read_file(file); free(file); - if (!buf) + if (!buf) { + free(name); return; + }
pevent_parse_event(perf_event::pevent, buf, strlen(buf), sys); free(name); diff --git a/src/tuning/bluetooth.cpp b/src/tuning/bluetooth.cpp index e0bdf12..5100a8a 100644 --- a/src/tuning/bluetooth.cpp +++ b/src/tuning/bluetooth.cpp @@ -144,8 +144,10 @@ int bt_tunable::good_bad(void) if (file) { char line[2048]; /* first line is standard header */ - if (fgets(line, 2047, file) == NULL) + if (fgets(line, 2047, file) == NULL) { + pclose(file); goto out; + } memset(line, 0, 2048); if (fgets(line, 2047, file) == NULL) { result = last_check_result = TUNE_GOOD;
-- Thanks, -Meraj
Mohammad,
This fix should go upstream. cc'ing the powertop list.
Regards, Amit
On Thu, Jun 26, 2014 at 12:42 PM, Mohammad Merajul Islam Molla meraj.enigma@gmail.com wrote:
Fixes some resource leaks detected by valgrind and coverity scan.
diff --git a/src/devices/ahci.cpp b/src/devices/ahci.cpp index ac06460..7f704b6 100644 --- a/src/devices/ahci.cpp +++ b/src/devices/ahci.cpp @@ -64,8 +64,10 @@ static string disk_name(char *path, char *target, char *shortname) sprintf(line, "%s/%s/model", pathname, dirent->d_name); file = fopen(line, "r"); if (file) {
if (fgets(line, 4096, file) == NULL)
if (fgets(line, 4096, file) == NULL) {
fclose(file); break;
} fclose(file); c = strchr(line, '\n'); if (c)
diff --git a/src/devices/devfreq.cpp b/src/devices/devfreq.cpp index e16951c..23c4b0c 100644 --- a/src/devices/devfreq.cpp +++ b/src/devices/devfreq.cpp @@ -238,6 +238,7 @@ void create_all_devfreq_devices(void)
callback fn = &devfreq_dev_callback; process_directory(p.c_str(), fn);
closedir(dir);
}
void initialize_devfreq(void) diff --git a/src/perf/perf_bundle.cpp b/src/perf/perf_bundle.cpp index b0e982b..cf1ae11 100644 --- a/src/perf/perf_bundle.cpp +++ b/src/perf/perf_bundle.cpp @@ -142,8 +142,10 @@ static void parse_event_format(const char *event_name)
buf = read_file(file); free(file);
if (!buf)
if (!buf) {
free(name); return;
} pevent_parse_event(perf_event::pevent, buf, strlen(buf), sys); free(name);
diff --git a/src/tuning/bluetooth.cpp b/src/tuning/bluetooth.cpp index e0bdf12..5100a8a 100644 --- a/src/tuning/bluetooth.cpp +++ b/src/tuning/bluetooth.cpp @@ -144,8 +144,10 @@ int bt_tunable::good_bad(void) if (file) { char line[2048]; /* first line is standard header */
if (fgets(line, 2047, file) == NULL)
if (fgets(line, 2047, file) == NULL) {
pclose(file); goto out;
} memset(line, 0, 2048); if (fgets(line, 2047, file) == NULL) { result = last_check_result = TUNE_GOOD;
-- Thanks, -Meraj
linaro-dev mailing list linaro-dev@lists.linaro.org http://lists.linaro.org/mailman/listinfo/linaro-dev
On (07/01/14 17:54), Amit Kucheria wrote:
Date: Tue, 1 Jul 2014 17:54:15 +0530 From: Amit Kucheria amit.kucheria@linaro.org To: Mohammad Merajul Islam Molla meraj.enigma@gmail.com, powertop@lists.01.org Cc: Lists linaro-dev linaro-dev@lists.linaro.org Subject: Re: [Powertop] [PATCH POWERTOP] Fix various resource leaks
Mohammad,
This fix should go upstream. cc'ing the powertop list.
Regards, Amit
On Thu, Jun 26, 2014 at 12:42 PM, Mohammad Merajul Islam Molla meraj.enigma@gmail.com wrote:
Fixes some resource leaks detected by valgrind and coverity scan.
diff --git a/src/devices/ahci.cpp b/src/devices/ahci.cpp index ac06460..7f704b6 100644 --- a/src/devices/ahci.cpp +++ b/src/devices/ahci.cpp @@ -64,8 +64,10 @@ static string disk_name(char *path, char *target, char *shortname) sprintf(line, "%s/%s/model", pathname, dirent->d_name); file = fopen(line, "r"); if (file) {
if (fgets(line, 4096, file) == NULL)
if (fgets(line, 4096, file) == NULL) {
fclose(file); break;
} fclose(file); c = strchr(line, '\n'); if (c)
diff --git a/src/devices/devfreq.cpp b/src/devices/devfreq.cpp index e16951c..23c4b0c 100644 --- a/src/devices/devfreq.cpp +++ b/src/devices/devfreq.cpp @@ -238,6 +238,7 @@ void create_all_devfreq_devices(void)
callback fn = &devfreq_dev_callback; process_directory(p.c_str(), fn);
closedir(dir);
I don't see this file at https://github.com/fenrus75/powertop/tree/master/src/devices
afair, process_directory() closes dir.
-ss
}
void initialize_devfreq(void) diff --git a/src/perf/perf_bundle.cpp b/src/perf/perf_bundle.cpp index b0e982b..cf1ae11 100644 --- a/src/perf/perf_bundle.cpp +++ b/src/perf/perf_bundle.cpp @@ -142,8 +142,10 @@ static void parse_event_format(const char *event_name)
buf = read_file(file); free(file);
if (!buf)
if (!buf) {
free(name); return;
} pevent_parse_event(perf_event::pevent, buf, strlen(buf), sys); free(name);
diff --git a/src/tuning/bluetooth.cpp b/src/tuning/bluetooth.cpp index e0bdf12..5100a8a 100644 --- a/src/tuning/bluetooth.cpp +++ b/src/tuning/bluetooth.cpp @@ -144,8 +144,10 @@ int bt_tunable::good_bad(void) if (file) { char line[2048]; /* first line is standard header */
if (fgets(line, 2047, file) == NULL)
if (fgets(line, 2047, file) == NULL) {
pclose(file); goto out;
} memset(line, 0, 2048); if (fgets(line, 2047, file) == NULL) { result = last_check_result = TUNE_GOOD;
-- Thanks, -Meraj
linaro-dev mailing list linaro-dev@lists.linaro.org http://lists.linaro.org/mailman/listinfo/linaro-dev
PowerTop mailing list PowerTop@lists.01.org https://lists.01.org/mailman/listinfo/powertop
I cloned powertop repo from - git://git.linaro.org/power/powertop-2.0.git. When I build and run, I see an additional tab "Device Freq stats" and powertop version shows 2.4.
I got the copy from github (pointed to by Sergey) now. When I build and run, I don't see any "Device Freq stats" tab and powertop version shows 2.6.1.
On Tue, Jul 1, 2014 at 6:47 PM, Sergey Senozhatsky sergey.senozhatsky@gmail.com wrote:
On (07/01/14 17:54), Amit Kucheria wrote:
Date: Tue, 1 Jul 2014 17:54:15 +0530 From: Amit Kucheria amit.kucheria@linaro.org To: Mohammad Merajul Islam Molla meraj.enigma@gmail.com, powertop@lists.01.org Cc: Lists linaro-dev linaro-dev@lists.linaro.org Subject: Re: [Powertop] [PATCH POWERTOP] Fix various resource leaks
Mohammad,
This fix should go upstream. cc'ing the powertop list.
Regards, Amit
On Thu, Jun 26, 2014 at 12:42 PM, Mohammad Merajul Islam Molla meraj.enigma@gmail.com wrote:
Fixes some resource leaks detected by valgrind and coverity scan.
diff --git a/src/devices/ahci.cpp b/src/devices/ahci.cpp index ac06460..7f704b6 100644 --- a/src/devices/ahci.cpp +++ b/src/devices/ahci.cpp @@ -64,8 +64,10 @@ static string disk_name(char *path, char *target, char *shortname) sprintf(line, "%s/%s/model", pathname, dirent->d_name); file = fopen(line, "r"); if (file) {
if (fgets(line, 4096, file) == NULL)
if (fgets(line, 4096, file) == NULL) {
fclose(file); break;
} fclose(file); c = strchr(line, '\n'); if (c)
diff --git a/src/devices/devfreq.cpp b/src/devices/devfreq.cpp index e16951c..23c4b0c 100644 --- a/src/devices/devfreq.cpp +++ b/src/devices/devfreq.cpp @@ -238,6 +238,7 @@ void create_all_devfreq_devices(void)
callback fn = &devfreq_dev_callback; process_directory(p.c_str(), fn);
closedir(dir);
I don't see this file at https://github.com/fenrus75/powertop/tree/master/src/devices
afair, process_directory() closes dir.
-ss
}
void initialize_devfreq(void) diff --git a/src/perf/perf_bundle.cpp b/src/perf/perf_bundle.cpp index b0e982b..cf1ae11 100644 --- a/src/perf/perf_bundle.cpp +++ b/src/perf/perf_bundle.cpp @@ -142,8 +142,10 @@ static void parse_event_format(const char *event_name)
buf = read_file(file); free(file);
if (!buf)
if (!buf) {
free(name); return;
} pevent_parse_event(perf_event::pevent, buf, strlen(buf), sys); free(name);
diff --git a/src/tuning/bluetooth.cpp b/src/tuning/bluetooth.cpp index e0bdf12..5100a8a 100644 --- a/src/tuning/bluetooth.cpp +++ b/src/tuning/bluetooth.cpp @@ -144,8 +144,10 @@ int bt_tunable::good_bad(void) if (file) { char line[2048]; /* first line is standard header */
if (fgets(line, 2047, file) == NULL)
if (fgets(line, 2047, file) == NULL) {
pclose(file); goto out;
} memset(line, 0, 2048); if (fgets(line, 2047, file) == NULL) { result = last_check_result = TUNE_GOOD;
-- Thanks, -Meraj
linaro-dev mailing list linaro-dev@lists.linaro.org http://lists.linaro.org/mailman/listinfo/linaro-dev
PowerTop mailing list PowerTop@lists.01.org https://lists.01.org/mailman/listinfo/powertop
Mohammad,
We've got a couple of patches that haven't been upstreamed yet. We'll get to it. Sorry I didn't notice that your patch was to that code.
Regards, Amit
On Wed, Jul 2, 2014 at 3:41 PM, Mohammad Merajul Islam Molla meraj.enigma@gmail.com wrote:
I cloned powertop repo from - git://git.linaro.org/power/powertop-2.0.git. When I build and run, I see an additional tab "Device Freq stats" and powertop version shows 2.4.
I got the copy from github (pointed to by Sergey) now. When I build and run, I don't see any "Device Freq stats" tab and powertop version shows 2.6.1.
On Tue, Jul 1, 2014 at 6:47 PM, Sergey Senozhatsky sergey.senozhatsky@gmail.com wrote:
On (07/01/14 17:54), Amit Kucheria wrote:
Date: Tue, 1 Jul 2014 17:54:15 +0530 From: Amit Kucheria amit.kucheria@linaro.org To: Mohammad Merajul Islam Molla meraj.enigma@gmail.com, powertop@lists.01.org Cc: Lists linaro-dev linaro-dev@lists.linaro.org Subject: Re: [Powertop] [PATCH POWERTOP] Fix various resource leaks
Mohammad,
This fix should go upstream. cc'ing the powertop list.
Regards, Amit
On Thu, Jun 26, 2014 at 12:42 PM, Mohammad Merajul Islam Molla meraj.enigma@gmail.com wrote:
Fixes some resource leaks detected by valgrind and coverity scan.
diff --git a/src/devices/ahci.cpp b/src/devices/ahci.cpp index ac06460..7f704b6 100644 --- a/src/devices/ahci.cpp +++ b/src/devices/ahci.cpp @@ -64,8 +64,10 @@ static string disk_name(char *path, char *target, char *shortname) sprintf(line, "%s/%s/model", pathname, dirent->d_name); file = fopen(line, "r"); if (file) {
if (fgets(line, 4096, file) == NULL)
if (fgets(line, 4096, file) == NULL) {
fclose(file); break;
} fclose(file); c = strchr(line, '\n'); if (c)
diff --git a/src/devices/devfreq.cpp b/src/devices/devfreq.cpp index e16951c..23c4b0c 100644 --- a/src/devices/devfreq.cpp +++ b/src/devices/devfreq.cpp @@ -238,6 +238,7 @@ void create_all_devfreq_devices(void)
callback fn = &devfreq_dev_callback; process_directory(p.c_str(), fn);
closedir(dir);
I don't see this file at https://github.com/fenrus75/powertop/tree/master/src/devices
afair, process_directory() closes dir.
-ss
}
void initialize_devfreq(void) diff --git a/src/perf/perf_bundle.cpp b/src/perf/perf_bundle.cpp index b0e982b..cf1ae11 100644 --- a/src/perf/perf_bundle.cpp +++ b/src/perf/perf_bundle.cpp @@ -142,8 +142,10 @@ static void parse_event_format(const char *event_name)
buf = read_file(file); free(file);
if (!buf)
if (!buf) {
free(name); return;
} pevent_parse_event(perf_event::pevent, buf, strlen(buf), sys); free(name);
diff --git a/src/tuning/bluetooth.cpp b/src/tuning/bluetooth.cpp index e0bdf12..5100a8a 100644 --- a/src/tuning/bluetooth.cpp +++ b/src/tuning/bluetooth.cpp @@ -144,8 +144,10 @@ int bt_tunable::good_bad(void) if (file) { char line[2048]; /* first line is standard header */
if (fgets(line, 2047, file) == NULL)
if (fgets(line, 2047, file) == NULL) {
pclose(file); goto out;
} memset(line, 0, 2048); if (fgets(line, 2047, file) == NULL) { result = last_check_result = TUNE_GOOD;
-- Thanks, -Meraj
linaro-dev mailing list linaro-dev@lists.linaro.org http://lists.linaro.org/mailman/listinfo/linaro-dev
PowerTop mailing list PowerTop@lists.01.org https://lists.01.org/mailman/listinfo/powertop
Hi Mohammad and Amit,
Mohammad,
This fix should go upstream. cc'ing the powertop list.
Regards, Amit
On Thu, Jun 26, 2014 at 12:42 PM, Mohammad Merajul Islam Molla meraj.enigma@gmail.com wrote:
Fixes some resource leaks detected by valgrind and coverity scan.
diff --git a/src/devices/ahci.cpp b/src/devices/ahci.cpp index ac06460..7f704b6 100644 --- a/src/devices/ahci.cpp +++ b/src/devices/ahci.cpp @@ -64,8 +64,10 @@ static string disk_name(char *path, char *target, char *shortname) sprintf(line, "%s/%s/model", pathname, dirent->d_name); file = fopen(line, "r"); if (file) {
if (fgets(line, 4096, file) == NULL)
if (fgets(line, 4096, file) == NULL) {
fclose(file); break;
} fclose(file); c = strchr(line, '\n'); if (c)
diff --git a/src/devices/devfreq.cpp b/src/devices/devfreq.cpp index e16951c..23c4b0c 100644 --- a/src/devices/devfreq.cpp +++ b/src/devices/devfreq.cpp @@ -238,6 +238,7 @@ void create_all_devfreq_devices(void)
callback fn = &devfreq_dev_callback; process_directory(p.c_str(), fn);
closedir(dir);
}
void initialize_devfreq(void) diff --git a/src/perf/perf_bundle.cpp b/src/perf/perf_bundle.cpp index b0e982b..cf1ae11 100644 --- a/src/perf/perf_bundle.cpp +++ b/src/perf/perf_bundle.cpp @@ -142,8 +142,10 @@ static void parse_event_format(const char *event_name)
buf = read_file(file); free(file);
if (!buf)
if (!buf) {
free(name); return;
} pevent_parse_event(perf_event::pevent, buf, strlen(buf), sys); free(name);
diff --git a/src/tuning/bluetooth.cpp b/src/tuning/bluetooth.cpp index e0bdf12..5100a8a 100644 --- a/src/tuning/bluetooth.cpp +++ b/src/tuning/bluetooth.cpp @@ -144,8 +144,10 @@ int bt_tunable::good_bad(void) if (file) { char line[2048]; /* first line is standard header */
if (fgets(line, 2047, file) == NULL)
if (fgets(line, 2047, file) == NULL) {
pclose(file); goto out;
} memset(line, 0, 2048); if (fgets(line, 2047, file) == NULL) { result = last_check_result = TUNE_GOOD;
-- Thanks, -Meraj
linaro-dev mailing list linaro-dev@lists.linaro.org http://lists.linaro.org/mailman/listinfo/linaro-dev
PowerTop mailing list PowerTop@lists.01.org https://lists.01.org/mailman/listinfo/powertop
Please send you patch against the tip of the tree. I'm having difficulties adding it:
Here is the error message: Patch is empty. Was it split wrong? If you would prefer to skip this patch, instead run "git am --skip". To restore the original branch and stop patching run "git am --abort".
Thank you, Alexandra.