Bug 244008

Summary: Leak of id<MTLArgumentEncoder> in rx::(anonymous)::InitArgumentBufferEncoder()
Product: WebKit Reporter: David Kilzer (:ddkilzer) <ddkilzer>
Component: ANGLEAssignee: David Kilzer (:ddkilzer) <ddkilzer>
Status: RESOLVED FIXED    
Severity: Normal CC: dino, kbr, kkinnunen, kpiddington, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 218877, 219260    
Bug Blocks:    

Description David Kilzer (:ddkilzer) 2022-08-16 14:04:36 PDT
Leak of id<MTLArgumentEncoder> in rx::(anonymous)::InitArgumentBufferEncoder().

The struct is defined like this in ProgramMtl.h:

```
struct ProgramArgumentBufferEncoderMtl
{
    void reset(ContextMtl *contextMtl);

    mtl::AutoObjCPtr<id<MTLArgumentEncoder>> metalArgBufferEncoder;
    mtl::BufferPool bufferPool;
};
```

However the method doesn't adopt the object in ProgramMtl.mm, which causes it to be assigned with a +2 retain count:

```
void InitArgumentBufferEncoder(mtl::Context *context,
                               id<MTLFunction> function,
                               uint32_t bufferIndex,
                               ProgramArgumentBufferEncoderMtl *encoder)
{
    encoder->metalArgBufferEncoder = [function newArgumentEncoderWithBufferIndex:bufferIndex];   // LEAK!
    if (encoder->metalArgBufferEncoder)
    {
        encoder->bufferPool.initialize(context, encoder->metalArgBufferEncoder.get().encodedLength,
                                       mtl::kArgumentBufferOffsetAlignment, 0);
    }
}
```
Comment 1 Radar WebKit Bug Importer 2022-08-16 14:05:06 PDT
<rdar://problem/98747531>
Comment 2 David Kilzer (:ddkilzer) 2022-08-16 14:07:06 PDT
This regressed in commit 6b271237a02594f551ab5948d7d2951addfda81f (232042@main) on Dec 02, 2020.
Comment 3 David Kilzer (:ddkilzer) 2022-08-16 14:43:47 PDT
Pull request: https://github.com/WebKit/WebKit/pull/3380
Comment 4 EWS 2022-08-17 11:14:06 PDT
Committed 253525@main (06f230986084): <https://commits.webkit.org/253525@main>

Reviewed commits have been landed. Closing PR #3380 and removing active labels.