Fix resource leak in visionbuf_free (#1699)
* fix resource leak in visionbuf_free * add mmap_len to VisionBuf
This commit is contained in:
parent
be08124d80
commit
a64f0119e0
|
@ -14,6 +14,7 @@ extern "C" {
|
|||
|
||||
typedef struct VisionBuf {
|
||||
size_t len;
|
||||
size_t mmap_len;
|
||||
void* addr;
|
||||
int handle;
|
||||
int fd;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <linux/ion.h>
|
||||
#include <CL/cl_ext.h>
|
||||
|
||||
|
@ -64,6 +64,7 @@ VisionBuf visionbuf_allocate(size_t len) {
|
|||
|
||||
return (VisionBuf){
|
||||
.len = len,
|
||||
.mmap_len = ion_alloc.len,
|
||||
.addr = addr,
|
||||
.handle = ion_alloc.handle,
|
||||
.fd = ion_fd_data.fd,
|
||||
|
@ -73,6 +74,7 @@ VisionBuf visionbuf_allocate(size_t len) {
|
|||
VisionBuf visionbuf_allocate_cl(size_t len, cl_device_id device_id, cl_context ctx, cl_mem *out_mem) {
|
||||
VisionBuf r = visionbuf_allocate(len);
|
||||
*out_mem = visionbuf_to_cl(&r, device_id, ctx);
|
||||
r.buf_cl = *out_mem;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -137,6 +139,9 @@ void visionbuf_sync(const VisionBuf* buf, int dir) {
|
|||
}
|
||||
|
||||
void visionbuf_free(const VisionBuf* buf) {
|
||||
clReleaseMemObject(buf->buf_cl);
|
||||
munmap(buf->addr, buf->mmap_len);
|
||||
close(buf->fd);
|
||||
struct ion_handle_data handle_data = {
|
||||
.handle = buf->handle,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue