From 72d64801543a3754a8ffd773af08a1752594fcef Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@orfeo-toolbox.org>
Date: Fri, 30 Jan 2015 13:44:12 +0100
Subject: [PATCH] COV: Fixing coverity issue 1267297 (Wrapper object used after
 free)

---
 Testing/Code/IO/otbGDALImageIOTestWriteMetadata.cxx | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Testing/Code/IO/otbGDALImageIOTestWriteMetadata.cxx b/Testing/Code/IO/otbGDALImageIOTestWriteMetadata.cxx
index ea35313d67..3cd06304e4 100644
--- a/Testing/Code/IO/otbGDALImageIOTestWriteMetadata.cxx
+++ b/Testing/Code/IO/otbGDALImageIOTestWriteMetadata.cxx
@@ -502,7 +502,8 @@ bool writeReadDatasetMetadata(std::string filename, std::vector<std::string> opt
     strIndexGCP << 1;
    
     std::string sstrIndexGCP = strIndexGCP.str();
-    gdalGcps[0].pszId = const_cast<char *>(sstrIndexGCP.c_str());
+    gdalGcps[0].pszId = new char[sstrIndexGCP.length()+1];
+    std::strcpy(gdalGcps[0].pszId,sstrIndexGCP.c_str());
     gdalGcps[0].pszInfo = const_cast<char *>("GCP test");
     gdalGcps[0].dfGCPPixel = 0.5;
     gdalGcps[0].dfGCPLine = 0.5;
@@ -512,6 +513,7 @@ bool writeReadDatasetMetadata(std::string filename, std::vector<std::string> opt
 
     poDstDS->SetGCPs(gcpCount, gdalGcps, pszSRS_WKT_GCP);
 
+    delete [] gdalGcps[0].pszId;
     delete[] gdalGcps;
 
     /*infoDatasetCreate->m_GCPProjRef = static_cast<std::string>( pszSRS_WKT);
-- 
GitLab