Skip to content

panics from unwrap causes memory leak on background threads with FFI #708

Open
@devtempmac

Description

@devtempmac

hello!
I've been using this library for some image processing, and some panics from unwraps in this library have causes leaks on my background threads. (and with rust threads defaulting to catch_unwind, they're practically invisible to me by default...)

would it be ok to add some 'safe' variants that return Result type instead of panicking?

eg)

pub fn draw_filled_rect<I>(image: &I, rect: Rect, color: I::Pixel) -> Image<I::Pixel>
where
    I: GenericImage,
{
    let mut out = Image::new(image.width(), image.height());
    out.copy_from(image, 0, 0).unwrap();
    draw_filled_rect_mut(&mut out, rect, color);
    out
}

would become:

pub fn draw_filled_rect_safe<I>(image: &I, rect: Rect, color: I::Pixel) -> ImageResult<Image<I::Pixel>>
where
    I: GenericImage,
{
    let mut out = ImageBuffer::new(image.width(), image.height());
    out.copy_from(image, 0, 0)?;
    draw_filled_rect_mut(&mut out, rect, color);
    Ok(out)
}

#[inline]
pub fn draw_filled_rect<I>(image: &I, rect: Rect, color: I::Pixel) -> Image<I::Pixel>
where
    I: GenericImage,
{
   return draw_filled_rect_safe(I, rect, color).unwrap();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions