Skip to content

Commit bcac881

Browse files
committed
Fix crash with 'gdal vector pipeline read my.shp --layer my ! sql --sql ... ! ...'
1 parent 68ade9c commit bcac881

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

apps/gdalalg_vector_read.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class GDALVectorPipelineReadOutputDataset final : public GDALDataset
4949

5050
public:
5151
explicit GDALVectorPipelineReadOutputDataset(GDALDataset &oSrcDS);
52+
~GDALVectorPipelineReadOutputDataset() override;
5253

5354
void AddLayer(OGRLayer &oSrcLayer);
5455

@@ -74,10 +75,20 @@ GDALVectorPipelineReadOutputDataset::GDALVectorPipelineReadOutputDataset(
7475
GDALDataset &srcDS)
7576
: m_srcDS(srcDS)
7677
{
78+
m_srcDS.Reference();
7779
SetDescription(m_srcDS.GetDescription());
7880
poDriver = m_srcDS.GetDriver();
7981
}
8082

83+
/************************************************************************/
84+
/* GDALVectorPipelineReadOutputDataset() */
85+
/************************************************************************/
86+
87+
GDALVectorPipelineReadOutputDataset::~GDALVectorPipelineReadOutputDataset()
88+
{
89+
m_srcDS.ReleaseRef();
90+
}
91+
8192
/************************************************************************/
8293
/* GDALVectorPipelineReadOutputDataset::AddLayer() */
8394
/************************************************************************/

autotest/utilities/test_gdalalg_vector_pipeline.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,3 +1080,14 @@ def test_gdalalg_vector_pipeline_decorated_ds_take_ref(tmp_vsimem):
10801080
ds = ogr.Open(f"{tmp_vsimem}/out.shp")
10811081
lyr = ds.GetLayer(0)
10821082
assert lyr.GetFeatureCount() == 1
1083+
1084+
1085+
def test_gdalalg_vector_pipeline_read_ds_take_ref(tmp_vsimem):
1086+
1087+
gdal.alg.vector.pipeline(
1088+
pipeline=f'read ../ogr/data/poly.shp ! read --layer poly ! sql --sql "select * from poly" ! write {tmp_vsimem}/out.shp'
1089+
)
1090+
1091+
ds = ogr.Open(f"{tmp_vsimem}/out.shp")
1092+
lyr = ds.GetLayer(0)
1093+
assert lyr.GetFeatureCount() == 10

0 commit comments

Comments
 (0)