Skip to content

Commit 6ccef05

Browse files
committed
MiraMonVector: Fix issue 393742177 oss-fuzz
Fixing a memory leak that happens in the case where polygon zero creates the database but some error occurs in the creation of the polygon zero. The database must be destroyed and created again next time the polygon zero is created. It's been reproduced in the case of skipFailures==true.
1 parent f82e760 commit 6ccef05

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

ogr/ogrsf_frmts/miramon/mm_wrlayr.c

+21
Original file line numberDiff line numberDiff line change
@@ -3729,6 +3729,7 @@ static int MMCreateFeaturePolOrArc(struct MiraMonVectLayerInfo *hMiraMonLayer,
37293729
MM_N_VERTICES_TYPE nPolVertices = 0;
37303730
MM_BOOLEAN bReverseArc;
37313731
int prevCoord = -1;
3732+
MM_BOOLEAN bPolZeroJustCreated = FALSE;
37323733

37333734
if (!hMiraMonLayer)
37343735
return MM_FATAL_ERROR_WRITING_FEATURES;
@@ -3824,7 +3825,16 @@ static int MMCreateFeaturePolOrArc(struct MiraMonVectLayerInfo *hMiraMonLayer,
38243825

38253826
// Universal polygon have a record with ID_GRAFIC=0 and blancs
38263827
if (MMAddPolygonRecordToMMDB(hMiraMonLayer, nullptr, 0, 0, nullptr))
3828+
{
3829+
// Rare case where polygon zero creates the database
3830+
// but some error occurs in the creation of the polygon zero.
3831+
// The database must be destroyed and created again
3832+
// next time the polygon zero is created.
3833+
MMCloseMMBD_XP(hMiraMonLayer);
3834+
MMDestroyMMDB(hMiraMonLayer);
38273835
return MM_FATAL_ERROR_WRITING_FEATURES;
3836+
}
3837+
bPolZeroJustCreated = TRUE;
38283838
}
38293839
}
38303840

@@ -3967,7 +3977,18 @@ static int MMCreateFeaturePolOrArc(struct MiraMonVectLayerInfo *hMiraMonLayer,
39673977
pCoord = hMMFeature->pCoord;
39683978

39693979
if (!pCoord)
3980+
{
3981+
if (bPolZeroJustCreated)
3982+
{
3983+
// Rare case where polygon zero creates the database
3984+
// but some error occurs in the creation of the polygon zero.
3985+
// The database must be destroyed and created again
3986+
// next time the polygon zero is created.
3987+
MMCloseMMBD_XP(hMiraMonLayer);
3988+
MMDestroyMMDB(hMiraMonLayer);
3989+
}
39703990
return MM_FATAL_ERROR_WRITING_FEATURES;
3991+
}
39713992

39723993
// Doing real job
39733994
for (nIPart = 0; nIPart < hMMFeature->nNRings; nIPart++,

0 commit comments

Comments
 (0)