Fix resource leak in visionbuf_free (#1699)

* fix resource leak in visionbuf_free

* add mmap_len to VisionBuf
old-commit-hash: a64f0119e0
commatwo_master
Dean Lee 5 years ago committed by GitHub
parent bb0d671eae
commit a4695dc837
  1. 1
      selfdrive/common/visionbuf.h
  2. 7
      selfdrive/common/visionbuf_ion.c

@ -14,6 +14,7 @@ extern "C" {
typedef struct VisionBuf { typedef struct VisionBuf {
size_t len; size_t len;
size_t mmap_len;
void* addr; void* addr;
int handle; int handle;
int fd; int fd;

@ -7,7 +7,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h>
#include <linux/ion.h> #include <linux/ion.h>
#include <CL/cl_ext.h> #include <CL/cl_ext.h>
@ -64,6 +64,7 @@ VisionBuf visionbuf_allocate(size_t len) {
return (VisionBuf){ return (VisionBuf){
.len = len, .len = len,
.mmap_len = ion_alloc.len,
.addr = addr, .addr = addr,
.handle = ion_alloc.handle, .handle = ion_alloc.handle,
.fd = ion_fd_data.fd, .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 visionbuf_allocate_cl(size_t len, cl_device_id device_id, cl_context ctx, cl_mem *out_mem) {
VisionBuf r = visionbuf_allocate(len); VisionBuf r = visionbuf_allocate(len);
*out_mem = visionbuf_to_cl(&r, device_id, ctx); *out_mem = visionbuf_to_cl(&r, device_id, ctx);
r.buf_cl = *out_mem;
return r; return r;
} }
@ -137,6 +139,9 @@ void visionbuf_sync(const VisionBuf* buf, int dir) {
} }
void visionbuf_free(const VisionBuf* buf) { 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 = { struct ion_handle_data handle_data = {
.handle = buf->handle, .handle = buf->handle,
}; };

Loading…
Cancel
Save