Skip to content

Commit

Permalink
MiraMonVector: Fix issue 393742177 oss-fuzz
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AbelPau committed Feb 3, 2025
1 parent f82e760 commit 6ccef05
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ogr/ogrsf_frmts/miramon/mm_wrlayr.c
Original file line number Diff line number Diff line change
Expand Up @@ -3729,6 +3729,7 @@ static int MMCreateFeaturePolOrArc(struct MiraMonVectLayerInfo *hMiraMonLayer,
MM_N_VERTICES_TYPE nPolVertices = 0;
MM_BOOLEAN bReverseArc;
int prevCoord = -1;
MM_BOOLEAN bPolZeroJustCreated = FALSE;

if (!hMiraMonLayer)
return MM_FATAL_ERROR_WRITING_FEATURES;
Expand Down Expand Up @@ -3824,7 +3825,16 @@ static int MMCreateFeaturePolOrArc(struct MiraMonVectLayerInfo *hMiraMonLayer,

// Universal polygon have a record with ID_GRAFIC=0 and blancs
if (MMAddPolygonRecordToMMDB(hMiraMonLayer, nullptr, 0, 0, nullptr))
{
// Rare 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.
MMCloseMMBD_XP(hMiraMonLayer);
MMDestroyMMDB(hMiraMonLayer);
return MM_FATAL_ERROR_WRITING_FEATURES;
}
bPolZeroJustCreated = TRUE;
}
}

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

if (!pCoord)
{
if (bPolZeroJustCreated)
{
// Rare 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.
MMCloseMMBD_XP(hMiraMonLayer);
MMDestroyMMDB(hMiraMonLayer);
}
return MM_FATAL_ERROR_WRITING_FEATURES;
}

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

0 comments on commit 6ccef05

Please sign in to comment.