From patchwork Tue Apr 25 16:45:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Starkey X-Patchwork-Id: 9698771 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CD5136020A for ; Tue, 25 Apr 2017 16:45:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC29F28636 for ; Tue, 25 Apr 2017 16:45:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B116D28660; Tue, 25 Apr 2017 16:45:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 67BEB28636 for ; Tue, 25 Apr 2017 16:45:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E433F6E5B1; Tue, 25 Apr 2017 16:45:26 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from foss.arm.com (foss.arm.com [217.140.101.70]) by gabe.freedesktop.org (Postfix) with ESMTP id 7EF406E5B6 for ; Tue, 25 Apr 2017 16:45:22 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 66718168F; Tue, 25 Apr 2017 09:45:22 -0700 (PDT) Received: from e106950-lin.cambridge.arm.com (e106950-lin.cambridge.arm.com [10.2.139.56]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C87DF3F4FF; Tue, 25 Apr 2017 09:45:21 -0700 (PDT) From: Brian Starkey To: intel-gfx@lists.freedesktop.org Date: Tue, 25 Apr 2017 17:45:09 +0100 Message-Id: <1493138713-2319-4-git-send-email-brian.starkey@arm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1493138713-2319-1-git-send-email-brian.starkey@arm.com> References: <1493138713-2319-1-git-send-email-brian.starkey@arm.com> Cc: liviu.dudau@arm.com Subject: [Intel-gfx] [PATCH i-g-t 3/7] lib: Stop igt_get_all_cairo_formats memory leak X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP igt_get_all_cairo_formats() allocates the format list on the heap, but returns it in a const pointer. Change this so that callers can free the array without a warning, and free the array in all callers. Signed-off-by: Brian Starkey --- lib/igt_fb.c | 4 +++- lib/igt_fb.h | 2 +- tests/kms_atomic.c | 3 ++- tests/kms_render.c | 4 +++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/igt_fb.c b/lib/igt_fb.c index d2b7e9e36606..b958c970973b 100644 --- a/lib/igt_fb.c +++ b/lib/igt_fb.c @@ -1277,8 +1277,10 @@ const char *igt_format_str(uint32_t drm_format) * * This functions returns an array of all the drm fourcc codes supported by * cairo and this library. + * + * The array should be freed by the caller. */ -void igt_get_all_cairo_formats(const uint32_t **formats, int *format_count) +void igt_get_all_cairo_formats(uint32_t **formats, int *format_count) { static uint32_t *drm_formats; static int n_formats; diff --git a/lib/igt_fb.h b/lib/igt_fb.h index 4a680cefb16d..e124910367a3 100644 --- a/lib/igt_fb.h +++ b/lib/igt_fb.h @@ -154,7 +154,7 @@ int igt_cairo_printf_line(cairo_t *cr, enum igt_text_align align, uint32_t igt_bpp_depth_to_drm_format(int bpp, int depth); uint32_t igt_drm_format_to_bpp(uint32_t drm_format); const char *igt_format_str(uint32_t drm_format); -void igt_get_all_cairo_formats(const uint32_t **formats, int *format_count); +void igt_get_all_cairo_formats(uint32_t **formats, int *format_count); #endif /* __IGT_FB_H__ */ diff --git a/tests/kms_atomic.c b/tests/kms_atomic.c index 6375fede7179..9c03f6e21ebb 100644 --- a/tests/kms_atomic.c +++ b/tests/kms_atomic.c @@ -807,7 +807,7 @@ static void atomic_state_free(struct kms_atomic_state *state) static uint32_t plane_get_igt_format(struct kms_atomic_plane_state *plane) { drmModePlanePtr plane_kms; - const uint32_t *igt_formats; + uint32_t *igt_formats; uint32_t ret = 0; int num_igt_formats; int i; @@ -827,6 +827,7 @@ static uint32_t plane_get_igt_format(struct kms_atomic_plane_state *plane) } } + free(igt_formats); drmModeFreePlane(plane_kms); return ret; } diff --git a/tests/kms_render.c b/tests/kms_render.c index fd33dfb7cafe..bc2ffc750c67 100644 --- a/tests/kms_render.c +++ b/tests/kms_render.c @@ -176,7 +176,7 @@ static void test_connector(const char *test_name, struct kmstest_connector_config *cconf, enum test_flags flags) { - const uint32_t *formats; + uint32_t *formats; int format_count; int i; @@ -193,6 +193,8 @@ static void test_connector(const char *test_name, cconf, &cconf->connector->modes[0], formats[i], flags); } + + free(formats); } static int run_test(const char *test_name, enum test_flags flags)