Skip to content

Commit 73218c8

Browse files
mbvreddyphausler
authored andcommitted
Fix memory leak in NSMutableData and NSData (#380)
1 parent 5983561 commit 73218c8

File tree

1 file changed

+4
-1
lines changed
  • CoreFoundation/Collections.subproj

1 file changed

+4
-1
lines changed

CoreFoundation/Collections.subproj/CFData.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,13 @@ CFTypeID CFDataGetTypeID(void) {
331331
CF_SWIFT_EXPORT void _CFDataInit(CFMutableDataRef memory, CFOptionFlags flags, CFIndex capacity, const uint8_t *bytes, CFIndex length, Boolean noCopy) {
332332
Boolean isMutable = ((flags & __kCFMutable) != 0);
333333
Boolean isGrowable = ((flags & __kCFGrowable) != 0);
334+
Boolean isDontDeallocate = ((flags & __kCFDontDeallocate) != 0);
334335

335336
__CFDataSetNumBytesUsed(memory, 0);
336337
__CFDataSetLength(memory, 0);
337-
__CFDataSetInfoBits(memory, __kCFDontDeallocate);
338+
if(isDontDeallocate) {
339+
__CFDataSetInfoBits(memory, __kCFDontDeallocate);
340+
}
338341

339342
if (isMutable && isGrowable) {
340343
__CFDataSetCapacity(memory, __CFDataRoundUpCapacity(1));

0 commit comments

Comments
 (0)