libdrm-meson: memory leak [1/1]
PD#SWPL-107344
Problem:
memleak using PES inyection via video/audio Decoders.
Solution:
Track the application and release process of function variable memory.
Verify:
View through valgrind.
Change-Id: I2a2ba35ae62367b5dc53362da8aaafa1f29c2473
Signed-off-by: chen.wang1 <chen.wang1@amlogic.com>
diff --git a/drm_fourcc.h b/drm_fourcc.h
index b8c6725..ae398db 100644
--- a/drm_fourcc.h
+++ b/drm_fourcc.h
@@ -54,7 +54,7 @@
* Format modifiers may change any property of the buffer, including the number
* of planes and/or the required allocation size. Format modifiers are
* vendor-namespaced, and as such the relationship between a fourcc code and a
- * modifier is specific to the modifer being used. For example, some modifiers
+ * modifier is specific to the modifier being used. For example, some modifiers
* may preserve meaning - such as number of planes - from the fourcc code,
* whereas others may not.
*
@@ -890,7 +890,7 @@
* Amlogic FBC Memory Saving mode
*
* Indicates the storage is packed when pixel size is multiple of word
- * boudaries, i.e. 8bit should be stored in this mode to save allocation
+ * boundaries, i.e. 8bit should be stored in this mode to save allocation
* memory.
*
* This mode reduces body layout to 3072 bytes per 64x32 superblock with
diff --git a/meson/meson_drm.c b/meson/meson_drm.c
index 91b4de2..50dd59e 100644
--- a/meson/meson_drm.c
+++ b/meson/meson_drm.c
@@ -41,10 +41,8 @@
strerror(errno));
return NULL;
}
-
dev->fd = fd;
- dev->render_fd = render_fd;
-
+ dev->render_fd = render_fd;
return dev;
}
@@ -83,8 +81,8 @@
fprintf(stderr, "invalid size.\n");
goto fail;
}
-
bo = calloc(sizeof(*bo), 1);
+ printf("meson_bo_create:%p\n",bo);
if (!bo) {
fprintf(stderr, "failed to create bo[%s].\n",
strerror(errno));
@@ -92,7 +90,7 @@
}
bo->dev = dev;
- fd = alloc_only ? dev->render_fd : dev->fd;
+ fd = alloc_only ? dev->render_fd : dev->fd;
if (drmIoctl(fd, DRM_IOCTL_MESON_GEM_CREATE, &req)) {
fprintf(stderr, "failed to create gem object[%s].\n",
@@ -103,7 +101,6 @@
bo->handle = req.handle;
bo->size = size;
bo->flags = flags;
-
return bo;
err_free_bo:
@@ -118,23 +115,19 @@
*/
void meson_bo_destroy(struct meson_bo *bo)
{
+ printf("meson_bo_destroy:%p\n",bo);
if (!bo)
return;
-
if (bo->vaddr)
munmap(bo->vaddr, bo->size);
-
if (bo->fd)
close(bo->fd);
-
if (bo->handle) {
struct drm_gem_close req = {
.handle = bo->handle,
};
-
drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_CLOSE, &req);
}
-
free(bo);
}
@@ -145,9 +138,8 @@
int meson_bo_dmabuf(struct meson_bo *bo, int alloc_only)
{
- int fd;
-
- fd = alloc_only ? bo->dev->render_fd : bo->dev->fd;
+ int fd;
+ fd = alloc_only ? bo->dev->render_fd : bo->dev->fd;
if (!bo->fd) {
struct drm_prime_handle req = {
.handle = bo->handle,
diff --git a/meson/meson_drm_kms.c b/meson/meson_drm_kms.c
index 451429a..65d07bd 100644
--- a/meson/meson_drm_kms.c
+++ b/meson/meson_drm_kms.c
@@ -23,6 +23,7 @@
struct kms_display;
+
#define VOID2U64(x) ((uint64_t)(unsigned long)(x))
#define container_of(ptr, type, member) \
(type *)((char *)(ptr) - (char *) &((type *)0)->member)
@@ -65,7 +66,6 @@
struct property src_y;
struct property src_w;
struct property src_h;
-
struct property type;
struct property in_fence_fd;
struct property in_formats;
@@ -125,7 +125,7 @@
for ( i = 0; i < buf->nbo; i++)
close(buf->fd[i]);
- fd = drm_disp->alloc_only ? drm_disp->dev->render_fd : drm_disp->dev->fd;
+ fd = drm_disp->alloc_only ? drm_disp->dev->render_fd : drm_disp->dev->fd;
drmModeRmFB(drm_disp->drm_fd, buf->fb_id);
memset(&destroy_dumb, 0, sizeof(destroy_dumb));
@@ -148,20 +148,19 @@
}
}
}
+ meson_bo_destroy(buf->bos[i]);
}
-
+ free(buf);
return 0;
}
static int kms_free_bufs(struct drm_display *drm_disp)
{
int i;
struct drm_buf *buf;
-
for ( i = 0; i < drm_disp->nbuf; i++ ) {
buf = &drm_disp->bufs[i];
free_buf(drm_disp, buf);
}
-
return 0;
}
@@ -293,15 +292,14 @@
return NULL;
}
- /*for non-root users, just need alloc buf and don't need to add framebuffer*/
- if (drm_disp->alloc_only)
- return buf;
+ /*for non-root users, just need alloc buf and don't need to add framebuffer*/
+ if (drm_disp->alloc_only)
+ return buf;
ret = add_framebuffer(drm_disp->drm_fd, buf, bo_handles, DRM_FORMAT_MOD_NONE);
if (ret) {
- fprintf(stderr, "add_framebuffer fail\n");
+ fprintf(stderr, "add_framebuffer fail, call free_buf\n");
free_buf(drm_disp, buf);
- free(buf);
return NULL;
}
@@ -517,7 +515,6 @@
p->value = props->prop_values[i];
//fprintf(stdout, "getproperty: %s, id: %u, value: %llu \n", res->name, p->id, p->value);
}
-
drmModeFreeProperty(res);
}
}
@@ -538,9 +535,10 @@
continue;
}
- if (connector->connector_type == DRM_MODE_CONNECTOR_TV)
+ if (connector->connector_type == DRM_MODE_CONNECTOR_TV) {
+ drmModeFreeConnector(connector);
continue;
-
+ }
state = calloc(1, sizeof(*state));
disp->conn_states[num_connector++] = state;
state->id = resources->connectors[i];
@@ -605,7 +603,6 @@
getproperty(disp->base.drm_fd, props, "ACTIVE", &state->active);
getproperty(disp->base.drm_fd, props, "OUT_FENCE_PTR", &state->out_fence);
getproperty(disp->base.drm_fd, props, "VIDEO_OUT_FENCE_PTR", &state->video_out_fence);
-
drmModeFreeObjectProperties(props);
} else {
fprintf(stderr, "get crtc obj property fail\n");
@@ -766,7 +763,7 @@
ret = populate_planes(resources, disp);
if (ret)
goto error1;
-
+ drmModeFreeResources(resources);
return 0;
error1:
@@ -802,7 +799,7 @@
base->import_buf = kms_import_buf;
base->free_buf = kms_free_buf;
base->post_buf = kms_post_buf;
- base->alloc_only = 0;
+ base->alloc_only = 0;
ret = drm_kms_init_resource(display);
if (ret) {