Fossil SCM

Fix another memory leak in the "fossil fusefs" command.

drh 2014-06-14 16:19 trunk
Commit 6b150197653b89e7d6ade1d1084cb98797da4a8e
1 file changed +28 -12
+28 -12
--- src/fusefs.c
+++ src/fusefs.c
@@ -49,23 +49,31 @@
4949
ManifestFile *pFile; /* Name of a cached file */
5050
Blob content; /* Content of the cached file */
5151
/* Parsed path */
5252
char *az[3]; /* 0=type, 1=id, 2=path */
5353
} fusefs;
54
+
55
+/*
56
+** Clear the fusefs.sz[] array.
57
+*/
58
+static void fusefs_clear_path(void){
59
+ int i;
60
+ for(i=0; i<count(fusefs.az); i++){
61
+ fossil_free(fusefs.az[i]);
62
+ fusefs.az[i] = 0;
63
+ }
64
+}
5465
5566
/*
5667
** Split of the input path into 0, 1, 2, or 3 elements in fusefs.az[].
5768
** Return the number of elements.
5869
**
5970
** Any prior path parse is deleted.
6071
*/
6172
static int fusefs_parse_path(const char *zPath){
6273
int i, j;
63
- for(i=0; i<count(fusefs.az); i++){
64
- fossil_free(fusefs.az[i]);
65
- fusefs.az[i] = 0;
66
- }
74
+ fusefs_clear_path();
6775
if( strcmp(zPath,"/")==0 ) return 0;
6876
for(i=0, j=1; i<2 && zPath[j]; i++){
6977
int jStart = j;
7078
while( zPath[j] && zPath[j]!='/' ){ j++; }
7179
fusefs.az[i] = mprintf("%.*s", j-jStart, &zPath[jStart]);
@@ -72,21 +80,30 @@
7280
if( zPath[j] ) j++;
7381
}
7482
if( zPath[j] ) fusefs.az[i++] = fossil_strdup(&zPath[j]);
7583
return i;
7684
}
85
+
86
+/*
87
+** Reclaim memory used by the fusefs local variable.
88
+*/
89
+static void fusefs_reset(void){
90
+ blob_reset(&fusefs.content);
91
+ manifest_destroy(fusefs.pMan);
92
+ fusefs.pMan = 0;
93
+ fossil_free(fusefs.zSymName);
94
+ fusefs.zSymName = 0;
95
+ fusefs.pFile = 0;
96
+}
7797
7898
/*
7999
** Load manifest rid into the cache.
80100
*/
81101
static void fusefs_load_rid(int rid, const char *zSymName){
82102
if( fusefs.rid==rid && fusefs.pMan!=0 ) return;
83
- blob_reset(&fusefs.content);
84
- manifest_destroy(fusefs.pMan);
85
- fossil_free(fusefs.zSymName);
103
+ fusefs_reset();
86104
fusefs.zSymName = fossil_strdup(zSymName);
87
- fusefs.pFile = 0;
88105
fusefs.pMan = manifest_get(rid, CFTYPE_MANIFEST, 0);
89106
fusefs.rid = rid;
90107
}
91108
92109
/*
@@ -216,10 +233,11 @@
216233
}
217234
cnt++;
218235
}
219236
pFile = manifest_file_next(fusefs.pMan, 0);
220237
}
238
+ fossil_free(zBase);
221239
}
222240
return cnt>0 ? 0 : -ENOENT;
223241
}
224242
225243
@@ -315,11 +333,9 @@
315333
azNewArgv[2] = "-s";
316334
azNewArgv[3] = zMountPoint;
317335
azNewArgv[4] = 0;
318336
g.localOpen = 0; /* Prevent tags like "current" and "prev" */
319337
fuse_main(4, azNewArgv, &fusefs_methods, NULL);
320
- manifest_destroy(fusefs.pMan);
321
- blob_reset(&fusefs.content);
322
- for(i=0; i<count(fusefs.az); i++) fossil_free(fusefs.az[i]);
323
- memset(&fusefs, 0, sizeof(fusefs));
338
+ fusefs_reset();
339
+ fusefs_clear_path();
324340
#endif
325341
}
326342
--- src/fusefs.c
+++ src/fusefs.c
@@ -49,23 +49,31 @@
49 ManifestFile *pFile; /* Name of a cached file */
50 Blob content; /* Content of the cached file */
51 /* Parsed path */
52 char *az[3]; /* 0=type, 1=id, 2=path */
53 } fusefs;
 
 
 
 
 
 
 
 
 
 
 
54
55 /*
56 ** Split of the input path into 0, 1, 2, or 3 elements in fusefs.az[].
57 ** Return the number of elements.
58 **
59 ** Any prior path parse is deleted.
60 */
61 static int fusefs_parse_path(const char *zPath){
62 int i, j;
63 for(i=0; i<count(fusefs.az); i++){
64 fossil_free(fusefs.az[i]);
65 fusefs.az[i] = 0;
66 }
67 if( strcmp(zPath,"/")==0 ) return 0;
68 for(i=0, j=1; i<2 && zPath[j]; i++){
69 int jStart = j;
70 while( zPath[j] && zPath[j]!='/' ){ j++; }
71 fusefs.az[i] = mprintf("%.*s", j-jStart, &zPath[jStart]);
@@ -72,21 +80,30 @@
72 if( zPath[j] ) j++;
73 }
74 if( zPath[j] ) fusefs.az[i++] = fossil_strdup(&zPath[j]);
75 return i;
76 }
 
 
 
 
 
 
 
 
 
 
 
 
77
78 /*
79 ** Load manifest rid into the cache.
80 */
81 static void fusefs_load_rid(int rid, const char *zSymName){
82 if( fusefs.rid==rid && fusefs.pMan!=0 ) return;
83 blob_reset(&fusefs.content);
84 manifest_destroy(fusefs.pMan);
85 fossil_free(fusefs.zSymName);
86 fusefs.zSymName = fossil_strdup(zSymName);
87 fusefs.pFile = 0;
88 fusefs.pMan = manifest_get(rid, CFTYPE_MANIFEST, 0);
89 fusefs.rid = rid;
90 }
91
92 /*
@@ -216,10 +233,11 @@
216 }
217 cnt++;
218 }
219 pFile = manifest_file_next(fusefs.pMan, 0);
220 }
 
221 }
222 return cnt>0 ? 0 : -ENOENT;
223 }
224
225
@@ -315,11 +333,9 @@
315 azNewArgv[2] = "-s";
316 azNewArgv[3] = zMountPoint;
317 azNewArgv[4] = 0;
318 g.localOpen = 0; /* Prevent tags like "current" and "prev" */
319 fuse_main(4, azNewArgv, &fusefs_methods, NULL);
320 manifest_destroy(fusefs.pMan);
321 blob_reset(&fusefs.content);
322 for(i=0; i<count(fusefs.az); i++) fossil_free(fusefs.az[i]);
323 memset(&fusefs, 0, sizeof(fusefs));
324 #endif
325 }
326
--- src/fusefs.c
+++ src/fusefs.c
@@ -49,23 +49,31 @@
49 ManifestFile *pFile; /* Name of a cached file */
50 Blob content; /* Content of the cached file */
51 /* Parsed path */
52 char *az[3]; /* 0=type, 1=id, 2=path */
53 } fusefs;
54
55 /*
56 ** Clear the fusefs.sz[] array.
57 */
58 static void fusefs_clear_path(void){
59 int i;
60 for(i=0; i<count(fusefs.az); i++){
61 fossil_free(fusefs.az[i]);
62 fusefs.az[i] = 0;
63 }
64 }
65
66 /*
67 ** Split of the input path into 0, 1, 2, or 3 elements in fusefs.az[].
68 ** Return the number of elements.
69 **
70 ** Any prior path parse is deleted.
71 */
72 static int fusefs_parse_path(const char *zPath){
73 int i, j;
74 fusefs_clear_path();
 
 
 
75 if( strcmp(zPath,"/")==0 ) return 0;
76 for(i=0, j=1; i<2 && zPath[j]; i++){
77 int jStart = j;
78 while( zPath[j] && zPath[j]!='/' ){ j++; }
79 fusefs.az[i] = mprintf("%.*s", j-jStart, &zPath[jStart]);
@@ -72,21 +80,30 @@
80 if( zPath[j] ) j++;
81 }
82 if( zPath[j] ) fusefs.az[i++] = fossil_strdup(&zPath[j]);
83 return i;
84 }
85
86 /*
87 ** Reclaim memory used by the fusefs local variable.
88 */
89 static void fusefs_reset(void){
90 blob_reset(&fusefs.content);
91 manifest_destroy(fusefs.pMan);
92 fusefs.pMan = 0;
93 fossil_free(fusefs.zSymName);
94 fusefs.zSymName = 0;
95 fusefs.pFile = 0;
96 }
97
98 /*
99 ** Load manifest rid into the cache.
100 */
101 static void fusefs_load_rid(int rid, const char *zSymName){
102 if( fusefs.rid==rid && fusefs.pMan!=0 ) return;
103 fusefs_reset();
 
 
104 fusefs.zSymName = fossil_strdup(zSymName);
 
105 fusefs.pMan = manifest_get(rid, CFTYPE_MANIFEST, 0);
106 fusefs.rid = rid;
107 }
108
109 /*
@@ -216,10 +233,11 @@
233 }
234 cnt++;
235 }
236 pFile = manifest_file_next(fusefs.pMan, 0);
237 }
238 fossil_free(zBase);
239 }
240 return cnt>0 ? 0 : -ENOENT;
241 }
242
243
@@ -315,11 +333,9 @@
333 azNewArgv[2] = "-s";
334 azNewArgv[3] = zMountPoint;
335 azNewArgv[4] = 0;
336 g.localOpen = 0; /* Prevent tags like "current" and "prev" */
337 fuse_main(4, azNewArgv, &fusefs_methods, NULL);
338 fusefs_reset();
339 fusefs_clear_path();
 
 
340 #endif
341 }
342

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button