Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MiraMonVector: fix Issue 369216702 #10872

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ogr/ogrsf_frmts/miramon/mm_wrlayr.c
Original file line number Diff line number Diff line change
Expand Up @@ -6255,6 +6255,11 @@ int MMCreateMMDB(struct MiraMonVectLayerInfo *hMiraMonLayer,
hMiraMonLayer->nSRSType = MM_SRS_LAYER_IS_GEOGRAPHIC_TYPE;
}

// Before allocating new memory, there might be some previously allocated but unused memory.
// Let's free that memory first.
if (hMiraMonLayer->MMArc.MMAdmDB.pMMBDXP)
MM_ReleaseDBFHeader(&hMiraMonLayer->MMArc.MMAdmDB.pMMBDXP);

if (hMiraMonLayer->bIsPoint)
{
if (hMiraMonLayer->pLayerDB)
Expand Down Expand Up @@ -6293,6 +6298,11 @@ int MMCreateMMDB(struct MiraMonVectLayerInfo *hMiraMonLayer,
: 9)))
return 1;

// Before allocating new memory, there might be some previously allocated but unused memory.
// Let's free that memory first.
if (hMiraMonLayer->MMArc.MMNode.MMAdmDB.pMMBDXP)
MM_ReleaseDBFHeader(&hMiraMonLayer->MMArc.MMNode.MMAdmDB.pMMBDXP);

pBD_XP_Aux = hMiraMonLayer->MMArc.MMNode.MMAdmDB.pMMBDXP =
MM_CreateDBFHeader(3, hMiraMonLayer->nCharSet);

Expand Down Expand Up @@ -6326,6 +6336,11 @@ int MMCreateMMDB(struct MiraMonVectLayerInfo *hMiraMonLayer,
: 12)))
return 1;

// Before allocating new memory, there might be some previously allocated but unused memory.
// Let's free that memory first.
if (hMiraMonLayer->MMArc.MMNode.MMAdmDB.pMMBDXP)
MM_ReleaseDBFHeader(&hMiraMonLayer->MMArc.MMNode.MMAdmDB.pMMBDXP);

pBD_XP_Aux = hMiraMonLayer->MMPolygon.MMArc.MMAdmDB.pMMBDXP =
MM_CreateDBFHeader(5, hMiraMonLayer->nCharSet);

Expand Down
21 changes: 19 additions & 2 deletions ogr/ogrsf_frmts/miramon/ogrmiramonlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,9 @@ OGRMiraMonLayer::~OGRMiraMonLayer()
if (MMCloseLayer(&hMiraMonLayerPOL))
{
CPLDebugOnly("MiraMon", "Error closing polygons layer");

// In case of closing we need to destroy memory
MMDestroyLayer(&hMiraMonLayerPOL);
}
if (hMiraMonLayerPOL.TopHeader.nElemCount)
{
Expand All @@ -548,6 +551,9 @@ OGRMiraMonLayer::~OGRMiraMonLayer()
if (MMCloseLayer(&hMiraMonLayerARC))
{
CPLDebugOnly("MiraMon", "Error closing arcs layer");

// In case of closing we need to destroy memory
MMDestroyLayer(&hMiraMonLayerARC);
}
if (hMiraMonLayerARC.TopHeader.nElemCount)
{
Expand All @@ -570,6 +576,9 @@ OGRMiraMonLayer::~OGRMiraMonLayer()
if (MMCloseLayer(&hMiraMonLayerPNT))
{
CPLDebugOnly("MiraMon", "Error closing points layer");

// In case of closing we need to destroy memory
MMDestroyLayer(&hMiraMonLayerPNT);
}
if (hMiraMonLayerPNT.TopHeader.nElemCount)
{
Expand All @@ -593,7 +602,11 @@ OGRMiraMonLayer::~OGRMiraMonLayer()
{
CPLDebugOnly("MiraMon", "Closing MiraMon DBF table ...");
}
MMCloseLayer(&hMiraMonLayerReadOrNonGeom);
if (MMCloseLayer(&hMiraMonLayerReadOrNonGeom))
{
// In case of closing we need to destroy memory
MMDestroyLayer(&hMiraMonLayerReadOrNonGeom);
}
if (hMiraMonLayerReadOrNonGeom.ReadOrWrite == MM_WRITING_MODE)
{
CPLDebugOnly("MiraMon", "MiraMon DBF table closed");
Expand All @@ -610,7 +623,11 @@ OGRMiraMonLayer::~OGRMiraMonLayer()
{
CPLDebugOnly("MiraMon", "Closing MiraMon layer ...");
}
MMCloseLayer(&hMiraMonLayerReadOrNonGeom);
if (MMCloseLayer(&hMiraMonLayerReadOrNonGeom))
{
// In case of closing we need to destroy memory
MMDestroyLayer(&hMiraMonLayerReadOrNonGeom);
}
if (hMiraMonLayerReadOrNonGeom.ReadOrWrite == MM_WRITING_MODE)
{
CPLDebugOnly("MiraMon", "MiraMon layer closed");
Expand Down
Loading