Skip to content

Commit 542e493

Browse files
AbelPaurouault
andcommitted
MiraMonVector: fix Issue 369216702
MiraMonVector: fix Issue 369216702 Co-Authored-By: Even Rouault <even.rouault@spatialys.com>
1 parent 388d97f commit 542e493

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

ogr/ogrsf_frmts/miramon/mm_wrlayr.c

+15
Original file line numberDiff line numberDiff line change
@@ -6255,6 +6255,11 @@ int MMCreateMMDB(struct MiraMonVectLayerInfo *hMiraMonLayer,
62556255
hMiraMonLayer->nSRSType = MM_SRS_LAYER_IS_GEOGRAPHIC_TYPE;
62566256
}
62576257

6258+
// Before allocating new memory, there might be some previously allocated but unused memory.
6259+
// Let's free that memory first.
6260+
if (hMiraMonLayer->MMArc.MMAdmDB.pMMBDXP)
6261+
MM_ReleaseDBFHeader(&hMiraMonLayer->MMArc.MMAdmDB.pMMBDXP);
6262+
62586263
if (hMiraMonLayer->bIsPoint)
62596264
{
62606265
if (hMiraMonLayer->pLayerDB)
@@ -6293,6 +6298,11 @@ int MMCreateMMDB(struct MiraMonVectLayerInfo *hMiraMonLayer,
62936298
: 9)))
62946299
return 1;
62956300

6301+
// Before allocating new memory, there might be some previously allocated but unused memory.
6302+
// Let's free that memory first.
6303+
if (hMiraMonLayer->MMArc.MMNode.MMAdmDB.pMMBDXP)
6304+
MM_ReleaseDBFHeader(&hMiraMonLayer->MMArc.MMNode.MMAdmDB.pMMBDXP);
6305+
62966306
pBD_XP_Aux = hMiraMonLayer->MMArc.MMNode.MMAdmDB.pMMBDXP =
62976307
MM_CreateDBFHeader(3, hMiraMonLayer->nCharSet);
62986308

@@ -6326,6 +6336,11 @@ int MMCreateMMDB(struct MiraMonVectLayerInfo *hMiraMonLayer,
63266336
: 12)))
63276337
return 1;
63286338

6339+
// Before allocating new memory, there might be some previously allocated but unused memory.
6340+
// Let's free that memory first.
6341+
if (hMiraMonLayer->MMArc.MMNode.MMAdmDB.pMMBDXP)
6342+
MM_ReleaseDBFHeader(&hMiraMonLayer->MMArc.MMNode.MMAdmDB.pMMBDXP);
6343+
63296344
pBD_XP_Aux = hMiraMonLayer->MMPolygon.MMArc.MMAdmDB.pMMBDXP =
63306345
MM_CreateDBFHeader(5, hMiraMonLayer->nCharSet);
63316346

ogr/ogrsf_frmts/miramon/ogrmiramonlayer.cpp

+19-2
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ OGRMiraMonLayer::~OGRMiraMonLayer()
527527
if (MMCloseLayer(&hMiraMonLayerPOL))
528528
{
529529
CPLDebugOnly("MiraMon", "Error closing polygons layer");
530+
531+
// In case of closing we need to destroy memory
532+
MMDestroyLayer(&hMiraMonLayerPOL);
530533
}
531534
if (hMiraMonLayerPOL.TopHeader.nElemCount)
532535
{
@@ -548,6 +551,9 @@ OGRMiraMonLayer::~OGRMiraMonLayer()
548551
if (MMCloseLayer(&hMiraMonLayerARC))
549552
{
550553
CPLDebugOnly("MiraMon", "Error closing arcs layer");
554+
555+
// In case of closing we need to destroy memory
556+
MMDestroyLayer(&hMiraMonLayerARC);
551557
}
552558
if (hMiraMonLayerARC.TopHeader.nElemCount)
553559
{
@@ -570,6 +576,9 @@ OGRMiraMonLayer::~OGRMiraMonLayer()
570576
if (MMCloseLayer(&hMiraMonLayerPNT))
571577
{
572578
CPLDebugOnly("MiraMon", "Error closing points layer");
579+
580+
// In case of closing we need to destroy memory
581+
MMDestroyLayer(&hMiraMonLayerPNT);
573582
}
574583
if (hMiraMonLayerPNT.TopHeader.nElemCount)
575584
{
@@ -593,7 +602,11 @@ OGRMiraMonLayer::~OGRMiraMonLayer()
593602
{
594603
CPLDebugOnly("MiraMon", "Closing MiraMon DBF table ...");
595604
}
596-
MMCloseLayer(&hMiraMonLayerReadOrNonGeom);
605+
if (MMCloseLayer(&hMiraMonLayerReadOrNonGeom))
606+
{
607+
// In case of closing we need to destroy memory
608+
MMDestroyLayer(&hMiraMonLayerReadOrNonGeom);
609+
}
597610
if (hMiraMonLayerReadOrNonGeom.ReadOrWrite == MM_WRITING_MODE)
598611
{
599612
CPLDebugOnly("MiraMon", "MiraMon DBF table closed");
@@ -610,7 +623,11 @@ OGRMiraMonLayer::~OGRMiraMonLayer()
610623
{
611624
CPLDebugOnly("MiraMon", "Closing MiraMon layer ...");
612625
}
613-
MMCloseLayer(&hMiraMonLayerReadOrNonGeom);
626+
if (MMCloseLayer(&hMiraMonLayerReadOrNonGeom))
627+
{
628+
// In case of closing we need to destroy memory
629+
MMDestroyLayer(&hMiraMonLayerReadOrNonGeom);
630+
}
614631
if (hMiraMonLayerReadOrNonGeom.ReadOrWrite == MM_WRITING_MODE)
615632
{
616633
CPLDebugOnly("MiraMon", "MiraMon layer closed");

0 commit comments

Comments
 (0)