Fossil SCM

Fix memory leaks in merge.

drh 2024-12-05 23:15 trunk
Commit 337617ba1973836a2fa2f403d6b0a2ca84987e88a1a2f9dad756eec21ec7dca3
2 files changed +8 -2 +1
+8 -2
--- src/merge3.c
+++ src/merge3.c
@@ -340,17 +340,21 @@
340340
mergebuilder_init_token(&mb);
341341
blob_extract_lines(pMB->pPivot, nPivot, &pv);
342342
blob_extract_lines(pMB->pV1, nV1, &v1);
343343
blob_extract_lines(pMB->pV2, nV2, &v2);
344344
blob_zero(pOut);
345
+ blob_materialize(&pv);
346
+ blob_materialize(&v1);
347
+ blob_materialize(&v2);
345348
mb.pPivot = &pv;
346349
mb.pV1 = &v1;
347350
mb.pV2 = &v2;
348351
mb.pOut = pOut;
349352
nConflict = merge_three_blobs(&mb);
350
- /* The pv, v1, and v2 blobs are all ephemeral and hence do not need
351
- ** to be freed. */
353
+ blob_reset(&pv);
354
+ blob_reset(&v1);
355
+ blob_reset(&v2);
352356
/* mb has not allocated any resources, so we do not need to invoke
353357
** the xDestroy method. */
354358
blob_add_final_newline(pOut);
355359
return nConflict;
356360
}
@@ -410,10 +414,11 @@
410414
411415
if( nRes>0 ){
412416
append_merge_mark(p->pOut, 1, 0, p->useCrLf);
413417
blob_copy_lines(p->pOut, &res, nRes);
414418
}
419
+ blob_reset(&res);
415420
416421
append_merge_mark(p->pOut, 2, p->lnPivot+1, p->useCrLf);
417422
blob_copy_lines(p->pOut, p->pPivot, nPivot); p->lnPivot += nPivot;
418423
419424
append_merge_mark(p->pOut, 3, p->lnV2+1, p->useCrLf);
@@ -1219,8 +1224,9 @@
12191224
}
12201225
fossil_free(zPivot);
12211226
fossil_free(zOrig);
12221227
fossil_free(zOther);
12231228
}
1229
+ blob_reset(&v1);
12241230
s.xDestroy(&s);
12251231
return rc;
12261232
}
12271233
--- src/merge3.c
+++ src/merge3.c
@@ -340,17 +340,21 @@
340 mergebuilder_init_token(&mb);
341 blob_extract_lines(pMB->pPivot, nPivot, &pv);
342 blob_extract_lines(pMB->pV1, nV1, &v1);
343 blob_extract_lines(pMB->pV2, nV2, &v2);
344 blob_zero(pOut);
 
 
 
345 mb.pPivot = &pv;
346 mb.pV1 = &v1;
347 mb.pV2 = &v2;
348 mb.pOut = pOut;
349 nConflict = merge_three_blobs(&mb);
350 /* The pv, v1, and v2 blobs are all ephemeral and hence do not need
351 ** to be freed. */
 
352 /* mb has not allocated any resources, so we do not need to invoke
353 ** the xDestroy method. */
354 blob_add_final_newline(pOut);
355 return nConflict;
356 }
@@ -410,10 +414,11 @@
410
411 if( nRes>0 ){
412 append_merge_mark(p->pOut, 1, 0, p->useCrLf);
413 blob_copy_lines(p->pOut, &res, nRes);
414 }
 
415
416 append_merge_mark(p->pOut, 2, p->lnPivot+1, p->useCrLf);
417 blob_copy_lines(p->pOut, p->pPivot, nPivot); p->lnPivot += nPivot;
418
419 append_merge_mark(p->pOut, 3, p->lnV2+1, p->useCrLf);
@@ -1219,8 +1224,9 @@
1219 }
1220 fossil_free(zPivot);
1221 fossil_free(zOrig);
1222 fossil_free(zOther);
1223 }
 
1224 s.xDestroy(&s);
1225 return rc;
1226 }
1227
--- src/merge3.c
+++ src/merge3.c
@@ -340,17 +340,21 @@
340 mergebuilder_init_token(&mb);
341 blob_extract_lines(pMB->pPivot, nPivot, &pv);
342 blob_extract_lines(pMB->pV1, nV1, &v1);
343 blob_extract_lines(pMB->pV2, nV2, &v2);
344 blob_zero(pOut);
345 blob_materialize(&pv);
346 blob_materialize(&v1);
347 blob_materialize(&v2);
348 mb.pPivot = &pv;
349 mb.pV1 = &v1;
350 mb.pV2 = &v2;
351 mb.pOut = pOut;
352 nConflict = merge_three_blobs(&mb);
353 blob_reset(&pv);
354 blob_reset(&v1);
355 blob_reset(&v2);
356 /* mb has not allocated any resources, so we do not need to invoke
357 ** the xDestroy method. */
358 blob_add_final_newline(pOut);
359 return nConflict;
360 }
@@ -410,10 +414,11 @@
414
415 if( nRes>0 ){
416 append_merge_mark(p->pOut, 1, 0, p->useCrLf);
417 blob_copy_lines(p->pOut, &res, nRes);
418 }
419 blob_reset(&res);
420
421 append_merge_mark(p->pOut, 2, p->lnPivot+1, p->useCrLf);
422 blob_copy_lines(p->pOut, p->pPivot, nPivot); p->lnPivot += nPivot;
423
424 append_merge_mark(p->pOut, 3, p->lnV2+1, p->useCrLf);
@@ -1219,8 +1224,9 @@
1224 }
1225 fossil_free(zPivot);
1226 fossil_free(zOrig);
1227 fossil_free(zOther);
1228 }
1229 blob_reset(&v1);
1230 s.xDestroy(&s);
1231 return rc;
1232 }
1233
+1
--- src/path.c
+++ src/path.c
@@ -542,10 +542,11 @@
542542
pChng = pAll;
543543
pAll = pAll->pNext;
544544
fossil_free(pChng);
545545
}
546546
}
547
+ path_reset();
547548
}
548549
549550
/*
550551
** COMMAND: test-name-changes
551552
**
552553
--- src/path.c
+++ src/path.c
@@ -542,10 +542,11 @@
542 pChng = pAll;
543 pAll = pAll->pNext;
544 fossil_free(pChng);
545 }
546 }
 
547 }
548
549 /*
550 ** COMMAND: test-name-changes
551 **
552
--- src/path.c
+++ src/path.c
@@ -542,10 +542,11 @@
542 pChng = pAll;
543 pAll = pAll->pNext;
544 fossil_free(pChng);
545 }
546 }
547 path_reset();
548 }
549
550 /*
551 ** COMMAND: test-name-changes
552 **
553

Keyboard Shortcuts

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