diff --git a/macosx/PiecesView.mm b/macosx/PiecesView.mm index a50af2e94..7d58972b6 100644 --- a/macosx/PiecesView.mm +++ b/macosx/PiecesView.mm @@ -2,6 +2,8 @@ // It may be used under the MIT (SPDX: MIT) license. // License text can be found in the licenses/ folder. +#include + #include #include @@ -26,7 +28,7 @@ enum @interface PiecesView () -@property(nonatomic) int8_t* fPieces; +@property(nonatomic) std::vector fPieces; @property(nonatomic) NSInteger fNumPieces; @property(nonatomic) NSInteger fAcross; @@ -57,7 +59,6 @@ enum - (void)dealloc { - tr_free(_fPieces); } - (void)setTorrent:(Torrent*)torrent @@ -84,8 +85,7 @@ enum - (void)clearView { - tr_free(self.fPieces); - self.fPieces = NULL; + self.fPieces.clear(); } - (void)updateView @@ -96,25 +96,25 @@ enum } //determine if first time - BOOL const first = self.fPieces == NULL; + BOOL const first = std::empty(self.fPieces); if (first) { - self.fPieces = (int8_t*)tr_malloc(self.fNumPieces * sizeof(int8_t)); + self.fPieces.resize(self.fNumPieces); } - int8_t* pieces = NULL; - float* piecesPercent = NULL; + auto pieces = std::vector{}; + auto piecesPercent = std::vector{}; BOOL const showAvailability = [NSUserDefaults.standardUserDefaults boolForKey:@"PiecesViewShowAvailability"]; if (showAvailability) { - pieces = (int8_t*)tr_malloc(self.fNumPieces * sizeof(int8_t)); - [self.torrent getAvailability:pieces size:self.fNumPieces]; + pieces.resize(self.fNumPieces); + [self.torrent getAvailability:std::data(pieces) size:std::size(pieces)]; } else { - piecesPercent = (float*)tr_malloc(self.fNumPieces * sizeof(float)); - [self.torrent getAmountFinished:piecesPercent size:self.fNumPieces]; + piecesPercent.resize(self.fNumPieces); + [self.torrent getAmountFinished:std::data(piecesPercent) size:std::size(piecesPercent)]; } NSImage* image = self.image; @@ -193,9 +193,6 @@ enum [image unlockFocus]; [self setNeedsDisplay]; } - - tr_free(pieces); - tr_free(piecesPercent); } - (BOOL)acceptsFirstMouse:(NSEvent*)event diff --git a/macosx/Torrent.mm b/macosx/Torrent.mm index f21b63dad..ae276dd29 100644 --- a/macosx/Torrent.mm +++ b/macosx/Torrent.mm @@ -3,6 +3,7 @@ // License text can be found in the licenses/ folder. #include +#include #include @@ -1535,14 +1536,14 @@ bool trashDataFile(char const* filename, tr_error** error) - (void)setFilePriority:(tr_priority_t)priority forIndexes:(NSIndexSet*)indexSet { NSUInteger const count = indexSet.count; - tr_file_index_t* files = static_cast(tr_malloc(count * sizeof(tr_file_index_t))); + auto files = std::vector{}; + files.resize(count); for (NSUInteger index = indexSet.firstIndex, i = 0; index != NSNotFound; index = [indexSet indexGreaterThanIndex:index], i++) { files[i] = index; } - tr_torrentSetFilePriorities(self.fHandle, files, count, priority); - tr_free(files); + tr_torrentSetFilePriorities(self.fHandle, std::data(files), std::size(files), priority); } - (BOOL)hasFilePriority:(tr_priority_t)priority forIndexes:(NSIndexSet*)indexSet diff --git a/qt/RpcClient.cc b/qt/RpcClient.cc index 1b5ca27db..90b1d6f71 100644 --- a/qt/RpcClient.cc +++ b/qt/RpcClient.cc @@ -16,7 +16,6 @@ #include #include -#include // tr_free #include // LONG_VERSION_STRING #include "VariantHelpers.h" @@ -31,15 +30,14 @@ namespace char const constexpr* const RequestDataPropertyKey{ "requestData" }; char const constexpr* const RequestFutureinterfacePropertyKey{ "requestReplyFutureInterface" }; -void destroyVariant(tr_variant* json) -{ - tr_variantFree(json); - tr_free(json); -} - TrVariantPtr createVariant() { - return { tr_new0(tr_variant, 1), &destroyVariant }; + return { new tr_variant{}, + [](tr_variant* var) + { + tr_variantFree(var); + delete var; + } }; } } // namespace