File: fd-leak-patch.txt

package info (click to toggle)
icewm 1.3.8+mod+20161220-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 7,160 kB
  • ctags: 5,575
  • sloc: cpp: 48,848; ansic: 1,813; makefile: 1,129; sh: 339; xml: 48
file content (75 lines) | stat: -rw-r--r-- 2,586 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
diff --git a/src/aapm.cc b/src/aapm.cc
index 8d9ca4d..50e25a1 100644
--- a/src/aapm.cc
+++ b/src/aapm.cc
@@ -602,7 +602,8 @@ void YApm::SysStr(char *s, bool Tool) {
         	fd = fopen(buf, "r");
 	}
 
-        if (fd != NULL && fgets(buf, sizeof(buf), fd)) {
+        if (fd != NULL) {
+	    if (fgets(buf, sizeof(buf), fd)) {
                 if (strncasecmp(buf, "charging", 8) == 0) {
                         BATstatus = BAT_CHARGING;
                     }
@@ -615,20 +616,24 @@ void YApm::SysStr(char *s, bool Tool) {
                     else {
                         BATstatus = BAT_UNKNOWN;
                     }
-                fclose(fd);
+	    }
+	    fclose(fd);
         }
+
         strcat3(buf, "/sys/class/power_supply/", BATname, "/current_now", sizeof(buf));
         fd = fopen(buf, "r");
         if (fd == NULL) {
             strcat3(buf, "/sys/class/power_supply/", BATname, "/power_now", sizeof(buf));
             fd = fopen(buf, "r");
 	}
-        if (fd != NULL && fgets(buf, sizeof(buf), fd)) {
+        if (fd != NULL) {
+	    if (fgets(buf, sizeof(buf), fd)) {
                 //In case it contains non-numeric value
                 if (sscanf(buf,"%d", &BATrate) <= 0) {
                     BATrate = -1;
                 }
-                fclose(fd);
+	    }
+	    fclose(fd);
         }
 
         strcat3(buf, "/sys/class/power_supply/", BATname, "/energy_now", sizeof(buf));
@@ -637,23 +642,28 @@ void YApm::SysStr(char *s, bool Tool) {
             strcat3(buf, "/sys/class/power_supply/", BATname, "/charge_now", sizeof(buf));
             fd = fopen(buf, "r");
         }
-        if (fd != NULL && fgets(buf, sizeof(buf), fd)) {
+        if (fd != NULL) {
+	    if (fgets(buf, sizeof(buf), fd)) {
                 //In case it contains non-numeric value
                 if (sscanf(buf,"%d", &BATcapacity_remain) <= 0) {
                     BATcapacity_remain = -1;
                 }
-                fclose(fd);
+	    }
+	    fclose(fd);
         }
+
         strcat3(buf, "/sys/class/power_supply/", BATname, "/present", sizeof(buf));
         fd = fopen(buf, "r");
-        if (fd != NULL && fgets(buf, sizeof(buf), fd)) {
+        if (fd != NULL) {
+	    if (fgets(buf, sizeof(buf), fd)) {
                 if (strncmp(buf, "1", 1) == 0) {
                     BATpresent = BAT_PRESENT;
                 }
                 else {
                     BATpresent = BAT_ABSENT;
                 }
-                fclose(fd);
+	    }
+	    fclose(fd);
         }
 
         if (BATpresent == BAT_PRESENT) { //battery is present now