Fossil SCM

Fix additional harmless memory leaks.

drh 2024-12-18 12:51 UTC trunk
Commit d564056cce59a70a41eb981eb23109b1dcffb290f0ef9e8329ef4d2c5d4b6ecc
+3 -4
--- src/checkout.c
+++ src/checkout.c
@@ -171,23 +171,22 @@
171171
** each character as a flag to enable writing "manifest", "manifest.uuid" or
172172
** "manifest.tags".
173173
*/
174174
void manifest_to_disk(int vid){
175175
char *zManFile;
176
- Blob manifest;
177
- Blob taglist;
178176
int flg;
179177
180178
flg = db_get_manifest_setting();
181179
182180
if( flg & MFESTFLG_RAW ){
183
- blob_zero(&manifest);
181
+ Blob manifest = BLOB_INITIALIZER;
184182
content_get(vid, &manifest);
185183
sterilize_manifest(&manifest, CFTYPE_MANIFEST);
186184
zManFile = mprintf("%smanifest", g.zLocalRoot);
187185
blob_write_to_file(&manifest, zManFile);
188186
free(zManFile);
187
+ blob_reset(&manifest);
189188
}else{
190189
if( !db_exists("SELECT 1 FROM vfile WHERE pathname='manifest'") ){
191190
zManFile = mprintf("%smanifest", g.zLocalRoot);
192191
file_delete(zManFile);
193192
free(zManFile);
@@ -207,11 +206,11 @@
207206
file_delete(zManFile);
208207
free(zManFile);
209208
}
210209
}
211210
if( flg & MFESTFLG_TAGS ){
212
- blob_zero(&taglist);
211
+ Blob taglist = BLOB_INITIALIZER;
213212
zManFile = mprintf("%smanifest.tags", g.zLocalRoot);
214213
get_checkin_taglist(vid, &taglist);
215214
blob_write_to_file(&taglist, zManFile);
216215
free(zManFile);
217216
blob_reset(&taglist);
218217
--- src/checkout.c
+++ src/checkout.c
@@ -171,23 +171,22 @@
171 ** each character as a flag to enable writing "manifest", "manifest.uuid" or
172 ** "manifest.tags".
173 */
174 void manifest_to_disk(int vid){
175 char *zManFile;
176 Blob manifest;
177 Blob taglist;
178 int flg;
179
180 flg = db_get_manifest_setting();
181
182 if( flg & MFESTFLG_RAW ){
183 blob_zero(&manifest);
184 content_get(vid, &manifest);
185 sterilize_manifest(&manifest, CFTYPE_MANIFEST);
186 zManFile = mprintf("%smanifest", g.zLocalRoot);
187 blob_write_to_file(&manifest, zManFile);
188 free(zManFile);
 
189 }else{
190 if( !db_exists("SELECT 1 FROM vfile WHERE pathname='manifest'") ){
191 zManFile = mprintf("%smanifest", g.zLocalRoot);
192 file_delete(zManFile);
193 free(zManFile);
@@ -207,11 +206,11 @@
207 file_delete(zManFile);
208 free(zManFile);
209 }
210 }
211 if( flg & MFESTFLG_TAGS ){
212 blob_zero(&taglist);
213 zManFile = mprintf("%smanifest.tags", g.zLocalRoot);
214 get_checkin_taglist(vid, &taglist);
215 blob_write_to_file(&taglist, zManFile);
216 free(zManFile);
217 blob_reset(&taglist);
218
--- src/checkout.c
+++ src/checkout.c
@@ -171,23 +171,22 @@
171 ** each character as a flag to enable writing "manifest", "manifest.uuid" or
172 ** "manifest.tags".
173 */
174 void manifest_to_disk(int vid){
175 char *zManFile;
 
 
176 int flg;
177
178 flg = db_get_manifest_setting();
179
180 if( flg & MFESTFLG_RAW ){
181 Blob manifest = BLOB_INITIALIZER;
182 content_get(vid, &manifest);
183 sterilize_manifest(&manifest, CFTYPE_MANIFEST);
184 zManFile = mprintf("%smanifest", g.zLocalRoot);
185 blob_write_to_file(&manifest, zManFile);
186 free(zManFile);
187 blob_reset(&manifest);
188 }else{
189 if( !db_exists("SELECT 1 FROM vfile WHERE pathname='manifest'") ){
190 zManFile = mprintf("%smanifest", g.zLocalRoot);
191 file_delete(zManFile);
192 free(zManFile);
@@ -207,11 +206,11 @@
206 file_delete(zManFile);
207 free(zManFile);
208 }
209 }
210 if( flg & MFESTFLG_TAGS ){
211 Blob taglist = BLOB_INITIALIZER;
212 zManFile = mprintf("%smanifest.tags", g.zLocalRoot);
213 get_checkin_taglist(vid, &taglist);
214 blob_write_to_file(&taglist, zManFile);
215 free(zManFile);
216 blob_reset(&taglist);
217
+1
--- src/main.c
+++ src/main.c
@@ -1330,10 +1330,11 @@
13301330
13311331
/* We should be done with options.. */
13321332
verify_all_options();
13331333
fossil_version_blob(&versionInfo, verboseFlag);
13341334
fossil_print("%s", blob_str(&versionInfo));
1335
+ blob_reset(&versionInfo);
13351336
}
13361337
13371338
13381339
/*
13391340
** WEBPAGE: version
13401341
--- src/main.c
+++ src/main.c
@@ -1330,10 +1330,11 @@
1330
1331 /* We should be done with options.. */
1332 verify_all_options();
1333 fossil_version_blob(&versionInfo, verboseFlag);
1334 fossil_print("%s", blob_str(&versionInfo));
 
1335 }
1336
1337
1338 /*
1339 ** WEBPAGE: version
1340
--- src/main.c
+++ src/main.c
@@ -1330,10 +1330,11 @@
1330
1331 /* We should be done with options.. */
1332 verify_all_options();
1333 fossil_version_blob(&versionInfo, verboseFlag);
1334 fossil_print("%s", blob_str(&versionInfo));
1335 blob_reset(&versionInfo);
1336 }
1337
1338
1339 /*
1340 ** WEBPAGE: version
1341
+8 -14
--- src/patch.c
+++ src/patch.c
@@ -81,13 +81,12 @@
8181
sqlite3_context *context,
8282
int argc,
8383
sqlite3_value **argv
8484
){
8585
const char *zFile;
86
- Blob x, y;
86
+ Blob x, y, out;
8787
int rid;
88
- char *aOut;
8988
int nOut;
9089
sqlite3_int64 sz;
9190
9291
rid = sqlite3_value_int(argv[0]);
9392
if( !content_get(rid, &x) ){
@@ -104,34 +103,29 @@
104103
if( sz<0 ){
105104
sqlite3_result_error(context, "mkdelta(X,Y): cannot read file Y", -1);
106105
blob_reset(&x);
107106
return;
108107
}
109
- aOut = sqlite3_malloc64(sz+70);
110
- if( aOut==0 ){
111
- sqlite3_result_error_nomem(context);
112
- blob_reset(&y);
113
- blob_reset(&x);
114
- return;
115
- }
108
+ blob_init(&out, 0, 0);
109
+ blob_resize(&out, sz+70);
116110
if( blob_size(&x)==blob_size(&y)
117111
&& memcmp(blob_buffer(&x), blob_buffer(&y), blob_size(&x))==0
118112
){
119113
blob_reset(&y);
120114
blob_reset(&x);
121115
sqlite3_result_blob64(context, "", 0, SQLITE_STATIC);
122116
return;
123117
}
124118
nOut = delta_create(blob_buffer(&x),blob_size(&x),
125
- blob_buffer(&y),blob_size(&y), aOut);
119
+ blob_buffer(&y),blob_size(&y), blob_buffer(&out));
120
+ blob_resize(&out, nOut);
126121
blob_reset(&x);
127122
blob_reset(&y);
128
- blob_init(&x, aOut, nOut);
129
- blob_compress(&x, &x);
130
- sqlite3_result_blob64(context, blob_buffer(&x), blob_size(&x),
123
+ blob_compress(&out, &out);
124
+ sqlite3_result_blob64(context, blob_buffer(&out), blob_size(&out),
131125
SQLITE_TRANSIENT);
132
- blob_reset(&x);
126
+ blob_reset(&out);
133127
}
134128
135129
136130
/*
137131
** Generate a binary patch file and store it into the file
138132
--- src/patch.c
+++ src/patch.c
@@ -81,13 +81,12 @@
81 sqlite3_context *context,
82 int argc,
83 sqlite3_value **argv
84 ){
85 const char *zFile;
86 Blob x, y;
87 int rid;
88 char *aOut;
89 int nOut;
90 sqlite3_int64 sz;
91
92 rid = sqlite3_value_int(argv[0]);
93 if( !content_get(rid, &x) ){
@@ -104,34 +103,29 @@
104 if( sz<0 ){
105 sqlite3_result_error(context, "mkdelta(X,Y): cannot read file Y", -1);
106 blob_reset(&x);
107 return;
108 }
109 aOut = sqlite3_malloc64(sz+70);
110 if( aOut==0 ){
111 sqlite3_result_error_nomem(context);
112 blob_reset(&y);
113 blob_reset(&x);
114 return;
115 }
116 if( blob_size(&x)==blob_size(&y)
117 && memcmp(blob_buffer(&x), blob_buffer(&y), blob_size(&x))==0
118 ){
119 blob_reset(&y);
120 blob_reset(&x);
121 sqlite3_result_blob64(context, "", 0, SQLITE_STATIC);
122 return;
123 }
124 nOut = delta_create(blob_buffer(&x),blob_size(&x),
125 blob_buffer(&y),blob_size(&y), aOut);
 
126 blob_reset(&x);
127 blob_reset(&y);
128 blob_init(&x, aOut, nOut);
129 blob_compress(&x, &x);
130 sqlite3_result_blob64(context, blob_buffer(&x), blob_size(&x),
131 SQLITE_TRANSIENT);
132 blob_reset(&x);
133 }
134
135
136 /*
137 ** Generate a binary patch file and store it into the file
138
--- src/patch.c
+++ src/patch.c
@@ -81,13 +81,12 @@
81 sqlite3_context *context,
82 int argc,
83 sqlite3_value **argv
84 ){
85 const char *zFile;
86 Blob x, y, out;
87 int rid;
 
88 int nOut;
89 sqlite3_int64 sz;
90
91 rid = sqlite3_value_int(argv[0]);
92 if( !content_get(rid, &x) ){
@@ -104,34 +103,29 @@
103 if( sz<0 ){
104 sqlite3_result_error(context, "mkdelta(X,Y): cannot read file Y", -1);
105 blob_reset(&x);
106 return;
107 }
108 blob_init(&out, 0, 0);
109 blob_resize(&out, sz+70);
 
 
 
 
 
110 if( blob_size(&x)==blob_size(&y)
111 && memcmp(blob_buffer(&x), blob_buffer(&y), blob_size(&x))==0
112 ){
113 blob_reset(&y);
114 blob_reset(&x);
115 sqlite3_result_blob64(context, "", 0, SQLITE_STATIC);
116 return;
117 }
118 nOut = delta_create(blob_buffer(&x),blob_size(&x),
119 blob_buffer(&y),blob_size(&y), blob_buffer(&out));
120 blob_resize(&out, nOut);
121 blob_reset(&x);
122 blob_reset(&y);
123 blob_compress(&out, &out);
124 sqlite3_result_blob64(context, blob_buffer(&out), blob_size(&out),
 
125 SQLITE_TRANSIENT);
126 blob_reset(&out);
127 }
128
129
130 /*
131 ** Generate a binary patch file and store it into the file
132

Keyboard Shortcuts

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