When the buffer objects (i.e. the generated parse tree of the SQL statement) is stored, it is stored in the buffer itself, not the underlying shared memory buffer. This leads to a memory leak when a buffer is cloned, the original buffer is parsed and then freed and finally the cloned buffer is freed.
The reference count of the shared memory buffer drops down to zero and the buffer objects are freed when the cloned buffer is being freed but the cloned buffer doesn't know about the buffer object that was created after the cloning process as the buffer objects are bound to individual buffers.
The fix to this is to make the buffer objects a part of the shared memory buffer, as I would suspect the original idea was.