Bug 244008 - Leak of id<MTLArgumentEncoder> in rx::(anonymous)::InitArgumentBufferEncoder()
Summary: Leak of id<MTLArgumentEncoder> in rx::(anonymous)::InitArgumentBufferEncoder()
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: ANGLE (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: David Kilzer (:ddkilzer)
URL:
Keywords: InRadar
Depends on: 218877 219260
Blocks:
  Show dependency treegraph
 
Reported: 2022-08-16 14:04 PDT by David Kilzer (:ddkilzer)
Modified: 2022-08-18 03:48 PDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.