Ticket #1189: patch_leaks.txt

File patch_leaks.txt, 5.4 KB (added by serval2412, 12 years ago)

proposed patch to fix these leaks

Line 
1Index: api/make_app_icon_h.cpp
2===================================================================
3--- api/make_app_icon_h.cpp     (révision 25749)
4+++ api/make_app_icon_h.cpp     (copie de travail)
5@@ -41,7 +41,7 @@
6     outFile = fopen(argv[2], "w");
7     if (inFile == NULL) {
8         printf ("Couldn't create output file %s\n", argv[2]);
9-        fclose(inFile);
10+        fclose(outFile);
11         return 0;
12     }
13     
14Index: api/texfont.cpp
15===================================================================
16--- api/texfont.cpp     (révision 25749)
17+++ api/texfont.cpp     (copie de travail)
18@@ -389,6 +389,12 @@
19                if (txf->teximage) free(txf->teximage);
20                free(txf);
21        }
22+       if (texbitmap) {
23+               free(texbitmap);
24+       }
25+       if (orig) {
26+               free(orig);
27+       }
28        if (file) fclose(file);
29        return NULL;
30 }
31Index: api/texture.cpp
32===================================================================
33--- api/texture.cpp     (révision 25749)
34+++ api/texture.cpp     (copie de travail)
35@@ -328,7 +328,10 @@
36        fread (&type, sizeof (char), 3, s);  // read in colormap info and image type, byte 0 ignored
37     fseek (s, 12, SEEK_SET);                    // seek past the header and useless info
38     fread (&info, sizeof (char), 6, s);
39-       if (type[1] != 0 || (type[2] != 2 && type[2] != 3)) return NULL;
40+       if (type[1] != 0 || (type[2] != 2 && type[2] != 3)) {
41+               fclose(s);
42+               return NULL;
43+       }
44        (*width)  = info[0] + info[1] * 256;
45     (*height) = info[2] + info[3] * 256;
46     imageBits =        info[4];
47Index: api/tgalib.cpp
48===================================================================
49--- api/tgalib.cpp      (révision 25749)
50+++ api/tgalib.cpp      (copie de travail)
51@@ -125,8 +125,11 @@
52                        }
53                }       
54                // Else return a NULL for a bad or unsupported pixel format
55-               else
56+               else {
57+                       free(pImageData);
58+                       fclose(pFile);
59                        return NULL;
60+               }
61        }
62        // Else, it must be Run-Length Encoded (RLE)
63        else
64Index: vda/vdad.cpp
65===================================================================
66--- vda/vdad.cpp        (révision 25749)
67+++ vda/vdad.cpp        (copie de travail)
68@@ -448,7 +448,10 @@
69     if (!f) return -1;
70     for (int i=0; i<policy.coding_levels; i++) {
71         int n = fscanf(f, "%lf\n", &(policy.chunk_sizes[i]));
72-        if (n != 1) return -1;
73+        if (n != 1) {
74+            fclose(f);
75+            return -1;
76+        }
77     }
78     fclose(f);
79     meta_chunk = new META_CHUNK(this, NULL, 0);
80Index: vda/vda_policy.cpp
81===================================================================
82--- vda/vda_policy.cpp  (révision 25749)
83+++ vda/vda_policy.cpp  (copie de travail)
84@@ -55,5 +55,6 @@
85     }
86     sprintf(buf, "X%d", replication);
87     strcat(description, buf);
88+    fclose(f);
89     return 0;
90 }
91Index: client/hostinfo_unix_test.cpp
92===================================================================
93--- client/hostinfo_unix_test.cpp       (révision 25749)
94+++ client/hostinfo_unix_test.cpp       (copie de travail)
95@@ -201,5 +201,6 @@
96 
97 
98     printf("p_vendor: %s\nm_cache: %d\nmodel_buf: %s\n", p_vendor, m_cache, model_buf);
99+    fclose(f);
100     return 0;
101 }
102Index: sched/sched_util.cpp
103===================================================================
104--- sched/sched_util.cpp        (révision 25749)
105+++ sched/sched_util.cpp        (copie de travail)
106@@ -140,6 +140,7 @@
107             return ERR_FOPEN;
108         }
109     }
110+    fclose(f);
111     return 0;
112 }
113 
114Index: sched/sched_main.cpp
115===================================================================
116--- sched/sched_main.cpp        (révision 25749)
117+++ sched/sched_main.cpp        (copie de travail)
118@@ -446,6 +446,9 @@
119             );
120         }
121 #endif
122+       if (stderr_buffer) {
123+            free(stderr_buffer);
124+       }
125     }
126 
127     srand(time(0)+getpid());
128Index: sched/sched_driver.cpp
129===================================================================
130--- sched/sched_driver.cpp      (révision 25749)
131+++ sched/sched_driver.cpp      (copie de travail)
132@@ -80,6 +80,7 @@
133         strcpy(hd.p_model, p3);
134         host_descs.push_back(hd);
135     }
136+    fclose(f);
137 }
138 
139 inline double req_time() {
140Index: sched/feeder.cpp
141===================================================================
142--- sched/feeder.cpp    (révision 25749)
143+++ sched/feeder.cpp    (copie de travail)
144@@ -873,6 +873,8 @@
145         weighted_interleave(
146             weights, ssp->napps, ssp->max_wu_results, app_indices, counts
147         );
148+        free(weights);
149+        free(counts);
150     } else {
151         napps = 1;
152     }
153Index: sched/credit_test.cpp
154===================================================================
155--- sched/credit_test.cpp       (révision 25749)
156+++ sched/credit_test.cpp       (copie de travail)
157@@ -351,6 +351,10 @@
158     double total_old_credit = 0;
159     double total_new_credit = 0;
160     FILE* in = fopen("credit_test_data", "r");
161+    if (in == NULL) {
162+        printf("Impossible to open credit_test_data\n");
163+        exit(1);
164+    }
165     printf("min credit: %f\n", min_credit);
166     while (!feof(in)) {
167         int c = fscanf(in, "%d %d %d %d %lf %d %lf %lf %lf %lf",
168@@ -400,6 +404,7 @@
169         }
170         if (n >= MAX_JOBS) break;
171     }
172+    fclose(in);
173     fclose(f);
174     if (nstats == 0) {
175         printf("Insufficient jobs were read from DB\n");
176Index: apps/concat.cpp
177===================================================================
178--- apps/concat.cpp     (révision 25749)
179+++ apps/concat.cpp     (copie de travail)
180@@ -121,6 +121,7 @@
181     if (state) {
182         fscanf(state, "%d %d", &file_num, &nchars);
183         mode = "a";
184+       fclose(state);
185     } else {
186         file_num = (run_slow ? 2 : 1);
187         nchars = 0;