Release decoder after command ahandler consumes bytes

This commit is contained in:
Anthony Kim
2026-02-08 00:16:01 -08:00
parent d320898231
commit 5ceb02b9c6
@@ -259,11 +259,17 @@ export class KittyGraphicsHandler implements IApcHandler, IResetHandler {
decodeError = true; decodeError = true;
} }
imageBytes = decoder.data8; imageBytes = decoder.data8;
decoder.release();
} }
this._activeDecoder = null; this._activeDecoder = null;
return this._handleCommandWithBytesAndCmd(finalCmd, imageBytes, decodeError); // Handle command first — handlers create Blob/ImageData from imageBytes,
// which copies the data. Only then is it safe to release the decoder's
// wasm memory that imageBytes points into.
const result = this._handleCommandWithBytesAndCmd(finalCmd, imageBytes, decodeError);
if (decoder) {
decoder.release();
}
return result;
} }
// Command handling // Command handling