From bc9bf75659e9b7b3d12acab4b5e74bda15a51f65 Mon Sep 17 00:00:00 2001 From: Mateusz Krawczuk Date: Mon, 22 Jun 2015 18:37:13 +0200 Subject: v4l2-mfc-example: Remove memory leak detected by valgrind Signed-off-by: Mateusz Krawczuk --- v4l2-mfc-example/drm.c | 4 ++-- v4l2-mfc-example/fimc.c | 15 ++++++++++----- v4l2-mfc-example/fimc.h | 2 +- v4l2-mfc-example/main.c | 8 ++++++-- v4l2-mfc-example/mfc.c | 19 ++++++++++++------- v4l2-mfc-example/mfc.h | 2 +- 6 files changed, 32 insertions(+), 18 deletions(-) diff --git a/v4l2-mfc-example/drm.c b/v4l2-mfc-example/drm.c index 35fad03..a7cc773 100644 --- a/v4l2-mfc-example/drm.c +++ b/v4l2-mfc-example/drm.c @@ -184,7 +184,7 @@ int drm_open(struct instance *i) i->drm.fb[n] = fb_id; } - snprintf(mode, 32, "%dx%d", crtc->width, crtc->height); + snprintf(mode, 32, "%dx%d", i->drm.width , i->drm.height); /* * Use detected Connector */ @@ -330,6 +330,7 @@ int dump_crtcs(struct instance *i) drmModeCrtc *crtc; int j,ret; + printf("CRTCs:\n"); printf("id\tfb\tpos\tsize\n"); for (j = 0; j < i->drm.resources->count_crtcs; j++) { @@ -348,7 +349,6 @@ int dump_crtcs(struct instance *i) crtc->width, crtc->height); drmModeFreeCrtc(crtc); } - printf("%i %i \n",crtc->crtc_id, ret); return ret; } diff --git a/v4l2-mfc-example/fimc.c b/v4l2-mfc-example/fimc.c index 30718e1..ed9dc87 100644 --- a/v4l2-mfc-example/fimc.c +++ b/v4l2-mfc-example/fimc.c @@ -27,6 +27,7 @@ #include #include +#include #include "common.h" #include "fimc.h" @@ -38,14 +39,15 @@ static char *dbg_type[2] = {"OUTPUT", "CAPTURE"}; static char *dbg_status[2] = {"ON", "OFF"}; -int fimc_open(struct instance *i, char *name) +int fimc_open(struct instance *i) { struct v4l2_capability cap; int ret; - i->fimc.fd = open(name, O_RDWR, 0); + i->fimc.fd = open(i->fimc.name, O_RDWR, 0); if (i->fimc.fd < 0) { - err("Failed to open FIMC: %s", name); + err("Failed to open FIMC: %s", i->fimc.name); + free(i->fimc.name); return -1; } @@ -57,16 +59,19 @@ int fimc_open(struct instance *i, char *name) } dbg("FIMC Info (%s): driver=\"%s\" bus_info=\"%s\" card=\"%s\" fd=0x%x", - name, cap.driver, cap.bus_info, cap.card, i->fimc.fd); + i->fimc.name, cap.driver, cap.bus_info, cap.card, i->fimc.fd); if ( !(((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE) && (cap.capabilities & V4L2_CAP_VIDEO_OUTPUT_MPLANE)) || (cap.capabilities & V4L2_CAP_VIDEO_M2M_MPLANE)) || !(cap.capabilities & V4L2_CAP_STREAMING)) { err("Insufficient capabilities of FIMC device (is %s correct?)", - name); + i->fimc.name); + free(i->fimc.name); + return -1; } + free(i->fimc.name); return 0; } diff --git a/v4l2-mfc-example/fimc.h b/v4l2-mfc-example/fimc.h index 5102547..41ba1da 100644 --- a/v4l2-mfc-example/fimc.h +++ b/v4l2-mfc-example/fimc.h @@ -26,7 +26,7 @@ #include "common.h" /* Open the FIMC device */ -int fimc_open(struct instance *i, char *name); +int fimc_open(struct instance *i); /* Close the FIMC device */ void fimc_close(struct instance *i); /* Set format in FIMC */ diff --git a/v4l2-mfc-example/main.c b/v4l2-mfc-example/main.c index 3f7c205..73b9ad7 100644 --- a/v4l2-mfc-example/main.c +++ b/v4l2-mfc-example/main.c @@ -126,6 +126,9 @@ int dequeue_capture(struct instance *i, int *n, int *finished) struct v4l2_plane planes[MFC_CAP_PLANES]; memzero(qbuf); + memzero(planes[0]); + memzero(planes[1]); + qbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; qbuf.memory = V4L2_MEMORY_MMAP; qbuf.m.planes = planes; @@ -526,6 +529,7 @@ int main(int argc, char **argv) printf("Kamil Debski \n"); printf("Copyright 2012-2015 Samsung Electronics Co., Ltd.\n\n"); + memzero(inst); if (parse_args(&inst, argc, argv)) { print_usage(argv[0]); return 1; @@ -547,12 +551,12 @@ int main(int argc, char **argv) return 1; } - if (inst.fimc.enabled && fimc_open(&inst, inst.fimc.name)) { + if (inst.fimc.enabled && fimc_open(&inst)) { cleanup(&inst); return 1; } - if (mfc_open(&inst, inst.mfc.name)) { + if (mfc_open(&inst)) { cleanup(&inst); return 1; } diff --git a/v4l2-mfc-example/mfc.c b/v4l2-mfc-example/mfc.c index 0511e3e..75bf8cb 100644 --- a/v4l2-mfc-example/mfc.c +++ b/v4l2-mfc-example/mfc.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "common.h" #include "mfc.h" @@ -36,14 +37,15 @@ static char *dbg_type[2] = {"OUTPUT", "CAPTURE"}; static char *dbg_status[2] = {"ON", "OFF"}; -int mfc_open(struct instance *i, char *name) +int mfc_open(struct instance *i) { struct v4l2_capability cap; int ret; - i->mfc.fd = open(name, O_RDWR, 0); + i->mfc.fd = open(i->mfc.name, O_RDWR, 0); if (i->mfc.fd < 0) { - err("Failed to open MFC: %s", name); + err("Failed to open MFC: %s", i->mfc.name); + free(i->mfc.name); return -1; } @@ -51,21 +53,23 @@ int mfc_open(struct instance *i, char *name) ret = ioctl(i->mfc.fd, VIDIOC_QUERYCAP, &cap); if (ret != 0) { err("Failed to verify capabilities"); + free(i->mfc.name); return -1; } dbg("MFC Info (%s): driver=\"%s\" bus_info=\"%s\" card=\"%s\" fd=0x%x", - name, cap.driver, cap.bus_info, cap.card, i->mfc.fd); + i->mfc.name, cap.driver, cap.bus_info, cap.card, i->mfc.fd); if ( !(((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE) && (cap.capabilities & V4L2_CAP_VIDEO_OUTPUT_MPLANE)) || (cap.capabilities & V4L2_CAP_VIDEO_M2M_MPLANE)) || !(cap.capabilities & V4L2_CAP_STREAMING)) { err("Insufficient capabilities of MFC device (is %s correct?)", - name); + i->mfc.name); + free(i->mfc.name); return -1; } - + free(i->mfc.name); return 0; } @@ -253,6 +257,7 @@ int mfc_dec_setup_capture(struct instance *i, int extra_buf) int ret; int n,d; + memzero(fmt); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; ret = ioctl(i->mfc.fd, VIDIOC_G_FMT, &fmt); if (ret) { @@ -265,7 +270,7 @@ int mfc_dec_setup_capture(struct instance *i, int extra_buf) i->mfc.cap_buf_size[0] = fmt.fmt.pix_mp.plane_fmt[0].sizeimage; i->mfc.cap_buf_size[1] = fmt.fmt.pix_mp.plane_fmt[1].sizeimage; - + memzero(ctrl); ctrl.id = V4L2_CID_MIN_BUFFERS_FOR_CAPTURE; ret = ioctl(i->mfc.fd, VIDIOC_G_CTRL, &ctrl); if (ret) { diff --git a/v4l2-mfc-example/mfc.h b/v4l2-mfc-example/mfc.h index a051f2a..74095b4 100644 --- a/v4l2-mfc-example/mfc.h +++ b/v4l2-mfc-example/mfc.h @@ -26,7 +26,7 @@ #include "common.h" /* Open the MFC device */ -int mfc_open(struct instance *i, char *name); +int mfc_open(struct instance *i); /* Close the MFC devices */ void mfc_close(struct instance *i); /* Setup the OUTPUT queue. The size determines the size for the stream -- cgit v1.2.3