Skip to content

Commit

Permalink
Add comment on detach use
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 12, 2018
1 parent a234bf7 commit 5158720
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/qgsogrutils.cpp
Expand Up @@ -226,8 +226,12 @@ QVariant QgsOgrUtils::getOgrFeatureAttribute( OGRFeatureH ogrFet, const QgsField
{
int size = 0;
const GByte *b = OGR_F_GetFieldAsBinary( ogrFet, attIndex, &size );

// QByteArray::fromRawData is funny. It doesn't take ownership of the data, so we have to explicitly call
// detach on it to force a copy which owns the data
QByteArray ba = QByteArray::fromRawData( reinterpret_cast<const char *>( b ), size );
ba.detach();

value = ba;
break;
}
Expand Down

0 comments on commit 5158720

Please sign in to comment.