Skip to content

[BUG] Potential log listener cleanup issue due to variable shadowing in ffmpeg.worker.ts #1460

@riya-chauhan12

Description

@riya-chauhan12

Description

While reviewing src/lib/ffmpeg.worker.ts, I noticed a possible issue with log listener cleanup in the non-GIF export flow.

A logListener variable is declared before the export logic:

let logListener: ((event: { message: string }) => void) | null = null;

Later, another logListener is declared and registered with FFmpeg:

const logListener = ({ message }: { message: string }) => {
  ...
};

ffmpeg.on("log", logListener);

However, the cleanup code in the finally block appears to reference the outer variable:

if (logListener) {
  ffmpeg.off("log", logListener);
}

Since the inner declaration shadows the outer one, it looks like the registered listener may not be the same reference used during cleanup.

File

src/lib/ffmpeg.worker.ts

Suggested Fix

Instead of redeclaring logListener, assign the callback to the existing variable so the same reference can be used for both registration and cleanup.

logListener = ({ message }) => {
  ...
};

ffmpeg.on("log", logListener);

I checked existing FFmpeg-related issues and found previous work around progress listener cleanup, but I couldn't find anything covering this specific log listener path.

Metadata

Metadata

Labels

bugSomething isn't working correctlytype:bugBug fixtype:refactorCode refactor

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions