vcl/ios/DataFlavorMapping.cxx | 11 +++++++++-- vcl/osx/DataFlavorMapping.cxx | 10 +++++++++- 2 files changed, 18 insertions(+), 3 deletions(-)
New commits: commit dd86e0a51a6539872f51a653580867bf0cfc22c5 Author: Patrick Luby <[email protected]> AuthorDate: Thu Jun 20 11:11:54 2024 -0400 Commit: Patrick Luby <[email protected]> CommitDate: Thu Jun 20 20:16:27 2024 +0200 tdf#161461 stop crashing by retaining NSString OUStringToNSString() returns an autoreleased NSString so it needs to be retained for the life of maOfficeOnlyTypes. Change-Id: Ic3777f818b7cada8e88e97965531fc0a7f2e825c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169284 Tested-by: Jenkins Reviewed-by: Patrick Luby <[email protected]> diff --git a/vcl/ios/DataFlavorMapping.cxx b/vcl/ios/DataFlavorMapping.cxx index 14bf0f6f43d7..607f110222bb 100644 --- a/vcl/ios/DataFlavorMapping.cxx +++ b/vcl/ios/DataFlavorMapping.cxx @@ -421,10 +421,17 @@ NSString* DataFlavorMapper::openOfficeToSystemFlavor(const DataFlavor& oOOFlavor OfficeOnlyTypes::const_iterator it = maOfficeOnlyTypes.find(oOOFlavor.MimeType); if (it == maOfficeOnlyTypes.end()) - sysFlavor = maOfficeOnlyTypes[oOOFlavor.MimeType] - = OUStringToNSString(oOOFlavor.MimeType); + { + // tdf#161461 stop crashing by retaining NSString + // OUStringToNSString() returns an autoreleased NSString so it + // needs to be retained for the life of maOfficeOnlyTypes. + sysFlavor = maOfficeOnlyTypes[oOOFlavor.MimeType] = + [OUStringToNSString(oOOFlavor.MimeType) retain]; + } else + { sysFlavor = it->second; + } } return sysFlavor; diff --git a/vcl/osx/DataFlavorMapping.cxx b/vcl/osx/DataFlavorMapping.cxx index d02582653f6d..16a2c8be9207 100644 --- a/vcl/osx/DataFlavorMapping.cxx +++ b/vcl/osx/DataFlavorMapping.cxx @@ -586,9 +586,17 @@ const NSString* DataFlavorMapper::openOfficeToSystemFlavor( const DataFlavor& oO OfficeOnlyTypes::const_iterator it = maOfficeOnlyTypes.find( oOOFlavor.MimeType ); if( it == maOfficeOnlyTypes.end() ) - sysFlavor = maOfficeOnlyTypes[ oOOFlavor.MimeType ] = OUStringToNSString( oOOFlavor.MimeType ); + { + // tdf#161461 stop crashing by retaining NSString + // OUStringToNSString() returns an autoreleased NSString so it + // needs to be retained for the life of maOfficeOnlyTypes. + sysFlavor = maOfficeOnlyTypes[oOOFlavor.MimeType] = + [OUStringToNSString(oOOFlavor.MimeType) retain]; + } else + { sysFlavor = it->second; + } } return sysFlavor;
