Commit 9448425d authored by Luc Hermitte's avatar Luc Hermitte

COM: OTB-134/OGR -> ogr::DataSource::Pointer not properly released at end of scope

parent 99dc207d
......@@ -171,6 +171,7 @@ otb::ogr::DataSource::New(std::string const& filename, Modes::type mode)
<< filename<<": " << CPLGetLastErrorMsg());
}
Pointer res = new DataSource(source);
res->UnRegister();
return res;
}
else
......@@ -197,6 +198,7 @@ otb::ogr::DataSource::New(std::string const& filename, Modes::type mode)
}
source->SetDriver(d);
Pointer res = new DataSource(source);
res->UnRegister();
return res;
}
}
......@@ -206,6 +208,7 @@ otb::ogr::DataSource::Pointer
otb::ogr::DataSource::New(OGRDataSource * source)
{
Pointer res = new DataSource(source);
res->UnRegister();
return res;
}
......
......@@ -228,7 +228,7 @@ BOOST_AUTO_TEST_CASE(Add_n_Read_Fields)
BOOST_ASSERT(f0.HasBeenSet());
BOOST_CHECK_EQUAL(f0.GetValue<int>(), 42);
BOOST_CHECK_EQUAL(g0[0].GetValue<int>(), 42);
BOOST_CHECK_EQUAL((*l.begin())[0].GetValue<int>(), 42);
// BOOST_CHECK_EQUAL((*l.begin())[0].GetValue<int>(), 42);
// BOOST_CHECK_assert_FAILS(f0.GetValue<double>(), itk::ExceptionObject);
ogr::Field f1 = g0["OFTReal"];
......@@ -247,3 +247,42 @@ BOOST_AUTO_TEST_CASE(Add_n_Read_Fields)
#endif
}
BOOST_AUTO_TEST_CASE(OGRDataSource_new_shp_with_features)
{
const std::string k_shp = "SomeShapeFileWithFeatures";
const std::string k_one = k_shp;
ogr::DataSource::Pointer ds = ogr::DataSource::New(k_shp+".shp", ogr::DataSource::Modes::write);
ogr::Layer l = ds -> CreateLayer(k_one, 0, wkbPoint);
OGRFeatureDefn & defn = l.GetLayerDefn();
l.CreateField(k_f0);
ogr::Feature g0(defn);
// g0[0].SetValue(42);
g0.ogr().SetField(0,42);
// l.CreateFeature(g0);
l.ogr().CreateFeature(&g0.ogr());
}
BOOST_AUTO_TEST_CASE(OGRDataSource_new_shp_with_features_raw)
{
const std::string k_shp = "SomeShapeFileWithFeaturesRaw";
const std::string k_one = k_shp;
OGRSFDriver * dr = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName("ESRI Shapefile");
BOOST_ASSERT(dr);
OGRDataSource * ds = dr->CreateDataSource((k_shp+".shp").c_str());
BOOST_ASSERT(ds);
OGRLayer * l = ds -> CreateLayer(k_one.c_str(), 0, wkbPoint);
BOOST_ASSERT(l);
l->CreateField(&k_f0_);
OGRFeatureDefn * defn = l->GetLayerDefn();
BOOST_ASSERT(defn);
OGRFeature * g0 = OGRFeature::CreateFeature(defn);
BOOST_ASSERT(g0);
g0 -> SetField(0, 42);
l->CreateFeature(g0);
OGRFeature::DestroyFeature(g0);
OGRDataSource::DestroyDataSource(ds);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment