Fix resource leak in visionbuf_free (#1699)

* fix resource leak in visionbuf_free

* add mmap_len to VisionBuf
This commit is contained in:
Dean Lee 2020-06-23 02:29:18 +08:00 committed by GitHub
parent be08124d80
commit a64f0119e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

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

View file

@ -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,
};