Skip to content

Close the probe frame from decoder.decode() to prevent resource leak. #49

@AStevensTaylor

Description

@AStevensTaylor

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

cat -n src/components/GifFrameExtractor.tsx | head -300 | tail -100

Repository: AStevensTaylor/image-tools

Length of output: 3390


🏁 Script executed:

# Get total line count first
wc -l src/components/GifFrameExtractor.tsx

Repository: AStevensTaylor/image-tools

Length of output: 110


🏁 Script executed:

# Look at the specific area around lines 254-255
sed -n '240,270p' src/components/GifFrameExtractor.tsx

Repository: AStevensTaylor/image-tools

Length of output: 708


🏁 Script executed:

# Also get context around the loop that processes frames
sed -n '270,320p' src/components/GifFrameExtractor.tsx

Repository: AStevensTaylor/image-tools

Length of output: 1254


🏁 Script executed:

# Check type definitions for ImageDecoder/DecodedFrame to understand API
rg "DecodedFrame|ImageDecoder" src/components/GifFrameExtractor.tsx -A 3 -B 1

Repository: AStevensTaylor/image-tools

Length of output: 1097


🏁 Script executed:

# Check if there are any imports or type definitions at the top of the file
head -50 src/components/GifFrameExtractor.tsx

Repository: AStevensTaylor/image-tools

Length of output: 1158


Close the probe frame from decoder.decode() to prevent resource leak.

The frame decoded at line 254 is not stored or closed, leaking resources. The existing code (lines 298–300) demonstrates the proper cleanup pattern already used for frames in the loop. Additionally, frame 0 is decoded twice unnecessarily (once as a probe, again in the loop).

Suggested fix
-				await decoder.decode({ frameIndex: 0 });
+				const probe = await decoder.decode({ frameIndex: 0 });
+				const probeFrame = probe.image as DecodedFrame;
+				if ("close" in probeFrame && typeof probeFrame.close === "function") {
+					probeFrame.close();
+				}
🤖 Prompt for AI Agents
In `@src/components/GifFrameExtractor.tsx` around lines 254 - 255, The probe
decode call to decoder.decode({ frameIndex: 0 }) currently discards the returned
frame and leaks resources; instead assign it to a variable (e.g., probeFrame),
perform the same cleanup used for loop frames (call probeFrame.close() after
isActive check), and avoid decoding frame 0 again by either starting the
subsequent frame loop at index 1 or skipping iteration when index === 0 so you
don't double-decode the same frame; refer to the existing decoder.decode and
frame.close() pattern used elsewhere in GifFrameExtractor.tsx to implement this.

Originally posted by @coderabbitai[bot] in #44 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions