Skip to content

Commit

Permalink
Fix use unref instead of free
Browse files Browse the repository at this point in the history
  • Loading branch information
MTRNord committed Jul 26, 2021
1 parent f6da016 commit 5d3b0a1
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ pub struct Camera {
impl Drop for Camera {
fn drop(&mut self) {
unsafe {
crate::gphoto2::gp_camera_exit(self.camera, self.context.context);
crate::gphoto2::gp_camera_free(self.camera);
crate::gphoto2::gp_camera_unref(self.camera);
crate::gphoto2::gp_context_unref(self.context.context);
}
}
Expand Down Expand Up @@ -67,6 +66,9 @@ impl Camera {
}
file_path.assume_init()
};
unsafe {
crate::gphoto2::gp_camera_exit(self.camera, self.context.context);
}
Ok(CameraFile { inner: file_path })
}

Expand All @@ -84,6 +86,9 @@ impl Camera {
destination.as_mut_ptr(),
self.context.as_mut_ptr())
};
unsafe {
crate::gphoto2::gp_camera_exit(self.camera, self.context.context);
}

Ok(())
}
Expand All @@ -100,6 +105,9 @@ impl Camera {

ptr.assume_init()
};
unsafe {
crate::gphoto2::gp_camera_exit(self.camera, self.context.context);
}
crate::port::from_libgphoto2(self, port_info)
}

Expand All @@ -115,6 +123,9 @@ impl Camera {
abilities.assume_init()
};

unsafe {
crate::gphoto2::gp_camera_exit(self.camera, self.context.context);
}
crate::abilities::from_libgphoto2(abilities)
}

Expand All @@ -140,6 +151,9 @@ impl Camera {
let storage = storage as *mut Storage;
let length = len as usize;

unsafe {
crate::gphoto2::gp_camera_exit(self.camera, self.context.context);
}
Ok(unsafe { Vec::from_raw_parts(storage, length, length) })
}

Expand Down Expand Up @@ -169,6 +183,9 @@ impl Camera {
summary.assume_init()
};

unsafe {
crate::gphoto2::gp_camera_exit(self.camera, self.context.context);
}
println!("Debug before free?");
util::camera_text_to_string(summary)
}
Expand Down Expand Up @@ -198,6 +215,9 @@ impl Camera {
manual.assume_init()
};

unsafe {
crate::gphoto2::gp_camera_exit(self.camera, self.context.context);
}
println!("Debug before free manual?");
util::camera_text_to_string(manual)
}
Expand Down Expand Up @@ -227,6 +247,9 @@ impl Camera {
about.assume_init()
};

unsafe {
crate::gphoto2::gp_camera_exit(self.camera, self.context.context);
}
println!("Debug before free about?");
util::camera_text_to_string(about)
}
Expand Down

0 comments on commit 5d3b0a1

Please sign in to comment.