Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-12581] function CMBlockBufferCreateWithMemoryBlock()'s memoryBlock parameter can't use &Data #4389

Closed
swift-ci opened this issue Apr 14, 2020 · 2 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-12581
Radar rdar://problem/62202310
Original Reporter 1442960012 (JIRA User)
Type Bug
Status Closed
Resolution Invalid
Environment

MacBook Air (Retina, 13-inch, 2018) MacOS Mojave 10.14.6
Xcode 11.3
iPhone XR iOS 12.1
Simulator iPhone8 iOS 13.3

Additional Detail from JIRA
Votes 0
Component/s Foundation, Standard Library
Labels Bug
Assignee None
Priority Medium

md5: b938231f1c4706b1b9cff131c0024b64

Issue Description:

Both return noErr OSStatus.

This is OK.

let dataBuffer:CMBlockBuffer={
    var buffer:CMBlockBuffer!
    CMBlockBufferCreateWithMemoryBlock(
        allocator: nil,
        memoryBlock: UnsafeMutableRawPointer(mutating: (bufferData as NSData).bytes),
        blockLength: bufferData.count,
        blockAllocator: kCFAllocatorNull,
        customBlockSource: nil, 
        offsetToData: 0,
        dataLength: bufferData.count,
        flags: 0, blockBufferOut: &buffer)
    return buffer
}()

This will cause memory leak when call VTDecompressionSessionDecodeFrame().

let dataBuffer:CMBlockBuffer={ 
    var buffer:CMBlockBuffer!
    CMBlockBufferCreateWithMemoryBlock(
        allocator: nil,
        memoryBlock: &bufferData,
        blockLength: bufferData.count,
        blockAllocator: kCFAllocatorNull,
        customBlockSource: nil,
        offsetToData: 0,
        dataLength: bufferData.count,
        flags: 0,
        blockBufferOut: &buffer)
    return buffer
}()
@beccadax
Copy link
Contributor

@swift-ci create

@swift-ci
Copy link
Contributor Author

Comment by Kyle Macomber (JIRA)

&bufferData passes a pointer to the local variable containing the Data struct not to Data’s bytes, which in this case appears to be a programmer error

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants