Commit fadb863e authored by Julien Osman's avatar Julien Osman

BUG: Avoid a memory leak and avoid returning const strings

parent 31ab00f5
......@@ -77,7 +77,7 @@ public:
* depends on the specific implementation. Returns empty string when path is not found,
* and hasValue is set to False.
* If band >= 0, the metadata value is looked in the specified band*/
virtual const std::string GetMetadataValue(const std::string path, bool& hasValue, int band=-1) const = 0;
virtual std::string GetMetadataValue(const std::string path, bool& hasValue, int band=-1) const = 0;
bool HasValue(std::string path, int band=-1);
......
......@@ -52,7 +52,7 @@ public:
* @param band not used
* @return The value corresponding to path. Empty string if not found.
*/
const std::string GetMetadataValue(const std::string path, bool& hasValue, int band=1) const override;
std::string GetMetadataValue(const std::string path, bool& hasValue, int band=1) const override;
/**
* @brief Get the first metadata value corresponding to a given path
......@@ -61,7 +61,7 @@ public:
* @param hasValue True if path is found
* @return The value corresponding to path. Empty string if not found.
*/
const std::string GetFirstMetadataValue(const std::string paths, bool& hasValue) const;
std::string GetFirstMetadataValue(const std::string paths, bool& hasValue) const;
/**
* @brief Get the metadata value corresponding to a given path
......
......@@ -36,7 +36,7 @@ XMLMetadataSupplier::XMLMetadataSupplier(const std::string & fileName)
CPLDestroyXMLNode(psNode);
}
const std::string XMLMetadataSupplier::GetMetadataValue(const std::string path, bool& hasValue, int band) const
std::string XMLMetadataSupplier::GetMetadataValue(const std::string path, bool& hasValue, int band) const
{
const char * ret = CSLFetchNameValue(m_MetadataDic, path.c_str());
if (ret)
......@@ -49,7 +49,7 @@ const std::string XMLMetadataSupplier::GetMetadataValue(const std::string path,
return std::string(ret);
}
const std::string XMLMetadataSupplier::GetFirstMetadataValue(const std::string path, bool& hasValue) const
std::string XMLMetadataSupplier::GetFirstMetadataValue(const std::string path, bool& hasValue) const
{
// Search for the first joker
std::size_t found = path.find("_#");
......@@ -74,9 +74,11 @@ const std::string XMLMetadataSupplier::GetFirstMetadataValue(const std::string p
if ((values != nullptr) && (values[0] != nullptr))
{
hasValue = true;
std::string ret = std::string(values[0]);
std::string ret = values[0];
ret = ret.substr(ret.find('=') + 1);
CSLDestroy(values);
// Return the value part
return ret.substr(ret.find('=') + 1);
return ret;
}
else
{
......
......@@ -210,7 +210,7 @@ public:
std::vector<std::string> GetResourceFiles() const override;
/** Get metadata item in GDALDataset, domain can specified as "domain/key" */
const std::string GetMetadataValue(const std::string path, bool& hasValue, int band = -1) const override;
std::string GetMetadataValue(const std::string path, bool& hasValue, int band = -1) const override;
/** Set metadata item in GDALDataset, domain can specified as prefix of the
* path, like "domain/key"*/
......
......@@ -1835,7 +1835,7 @@ std::vector<std::string> GDALImageIO::GetResourceFiles() const
return result;
}
const std::string GDALImageIO::GetMetadataValue(const std::string path, bool& hasValue, int band) const
std::string GDALImageIO::GetMetadataValue(const std::string path, bool& hasValue, int band) const
{
// detect namespace if any
std::string domain("");
......
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