Skip to content

Commit

Permalink
memory leak fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
leemaguire committed Mar 30, 2023
1 parent 79586cb commit 7042304
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ x.y.z Release notes (yyyy-MM-dd)
* None.

### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-swift/issues/????), since v?.?.?)
* None.
* Address memory leaks caused by `URL.path` in `Realm.Configuration.fileURL` and std::string bytes being
incorrectly captured when using a string partition key in Partition Based Sync ([#8195](https://github.com/realm/realm-swift/pull/8195)), since v10.0.0).

<!-- ### Breaking Changes - ONLY INCLUDE FOR NEW MAJOR version -->

Expand Down
2 changes: 1 addition & 1 deletion Realm/RLMBSON.mm
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ Bson RLMConvertRLMBSONToBson(id<RLMBSON> b) {
case realm::bson::Bson::Type::Double:
return @(static_cast<double>(b));
case realm::bson::Bson::Type::String:
return RLMStringDataToNSString(static_cast<std::string>(b).c_str());
return @(static_cast<std::string>(b).c_str());
case realm::bson::Bson::Type::Binary:
return [[NSData alloc] initWithBsonBinary:static_cast<std::vector<char>>(b)];
case realm::bson::Bson::Type::Timestamp:
Expand Down
12 changes: 3 additions & 9 deletions RealmSwift/RealmConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,25 +123,19 @@ extension Realm {

/// The local URL of the Realm file. Mutually exclusive with `inMemoryIdentifier`.
public var fileURL: URL? {
get {
return _path.map { URL(fileURLWithPath: $0) }
}
set {
didSet {
_inMemoryIdentifier = nil
_path = newValue?.path
}
}

private var _path: String?

/// A string used to identify a particular in-memory Realm. Mutually exclusive with `fileURL` and
/// `syncConfiguration`.
public var inMemoryIdentifier: String? {
get {
return _inMemoryIdentifier
}
set {
_path = nil
fileURL = nil
_syncConfiguration = nil
_inMemoryIdentifier = newValue
}
Expand Down Expand Up @@ -329,7 +323,7 @@ extension Realm {

internal static func fromRLMRealmConfiguration(_ rlmConfiguration: RLMRealmConfiguration) -> Configuration {
var configuration = Configuration()
configuration._path = rlmConfiguration.fileURL?.path
configuration.fileURL = rlmConfiguration.fileURL
configuration._inMemoryIdentifier = rlmConfiguration.inMemoryIdentifier
configuration._syncConfiguration = rlmConfiguration.syncConfiguration.map(SyncConfiguration.init(config:))
configuration.encryptionKey = rlmConfiguration.encryptionKey
Expand Down

0 comments on commit 7042304

Please sign in to comment.