From patchwork Wed Dec 31 13:28:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Holmes X-Patchwork-Id: 42656 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f197.google.com (mail-we0-f197.google.com [74.125.82.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B08B526CB8 for ; Wed, 31 Dec 2014 13:28:43 +0000 (UTC) Received: by mail-we0-f197.google.com with SMTP id w61sf1282704wes.4 for ; Wed, 31 Dec 2014 05:28:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=G17GVLJSVy85RqXgPrr0+mYBxMTolqF/0giBrRaDjF4=; b=C4PkHXcRoonOuUh71i4bmpiVtS6MZUbGOJ2nI1b7eutQCHbJ6EwDuu7bPWPW5cDj0A 5A5MJcP0HOwtKont2d7V7w5JFeTY6A4Xza2clSxcU/RgJPa8tDTYt/yMDF2VxqLxNpMh ZBb0DfwjF57L1q8X4UeOf9ywSfxBEmj+eQ+s0dAZCoBopmJyDUVOerYCIXZR7MmSTuYo gydUhpjy2da+5xjGcKEoxUJ5zhbF6C/JaJEXgRgP1Z2ipyMn89HXNtWE7ZQAypTWDydn vKSW8MiVU67us8UfPw7ik4aguseg0EW6rkXzoC9ak3sc6vNK7LADLKdC6aVrUMg8OF1c NvHw== X-Gm-Message-State: ALoCoQlY3Nc6U8d0/4HFyQqZix8jqrVCiyIkA/LLql7I1K8K680uALdy103EsBZMn+tDLkXOyfHb X-Received: by 10.180.108.101 with SMTP id hj5mr7090996wib.3.1420032523014; Wed, 31 Dec 2014 05:28:43 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.166 with SMTP id t6ls727272lat.38.gmail; Wed, 31 Dec 2014 05:28:42 -0800 (PST) X-Received: by 10.152.6.67 with SMTP id y3mr66474965lay.90.1420032522684; Wed, 31 Dec 2014 05:28:42 -0800 (PST) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id lk10si33413752lac.5.2014.12.31.05.28.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 31 Dec 2014 05:28:42 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by mail-lb0-f178.google.com with SMTP id f15so15022147lbj.37 for ; Wed, 31 Dec 2014 05:28:42 -0800 (PST) X-Received: by 10.112.131.1 with SMTP id oi1mr65317550lbb.2.1420032522251; Wed, 31 Dec 2014 05:28:42 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.142.69 with SMTP id ru5csp3364694lbb; Wed, 31 Dec 2014 05:28:41 -0800 (PST) X-Received: by 10.229.126.129 with SMTP id c1mr109030571qcs.12.1420032520880; Wed, 31 Dec 2014 05:28:40 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id s18si26374836qgs.92.2014.12.31.05.28.39 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 31 Dec 2014 05:28:40 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y6JKH-0000z3-NO; Wed, 31 Dec 2014 13:28:37 +0000 Received: from mail-qa0-f43.google.com ([209.85.216.43]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y6JKB-0000yw-6c for lng-odp@lists.linaro.org; Wed, 31 Dec 2014 13:28:31 +0000 Received: by mail-qa0-f43.google.com with SMTP id n4so8105825qaq.30 for ; Wed, 31 Dec 2014 05:28:26 -0800 (PST) X-Received: by 10.224.21.133 with SMTP id j5mr110260910qab.83.1420032505985; Wed, 31 Dec 2014 05:28:25 -0800 (PST) Received: from localhost.localdomain ([98.221.136.245]) by mx.google.com with ESMTPSA id k102sm18213235qgd.7.2014.12.31.05.28.25 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 Dec 2014 05:28:25 -0800 (PST) From: Mike Holmes To: lng-odp@lists.linaro.org Date: Wed, 31 Dec 2014 08:28:16 -0500 Message-Id: <1420032496-30645-1-git-send-email-mike.holmes@linaro.org> X-Mailer: git-send-email 2.1.0 X-Topics: patch Subject: [lng-odp] [PATCH] linux-generic: odp_linux: fix memory leak X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: mike.holmes@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Store the start_args so that they can be freed on join Fixes numerous leaks reported by valgrind Signed-off-by: Mike Holmes --- helper/include/odph_linux.h | 9 +++++++++ platform/linux-generic/odp_linux.c | 21 +++++++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/helper/include/odph_linux.h b/helper/include/odph_linux.h index 8671dc0..1b32b26 100644 --- a/helper/include/odph_linux.h +++ b/helper/include/odph_linux.h @@ -26,11 +26,20 @@ extern "C" { #include #include +/** The thread starting arguments */ +typedef struct { + void *(*start_routine) (void *); /**< The function to run */ + void *arg; /**< The functions arguemnts */ + +} odp_start_args_t; + /** Linux pthread state information */ typedef struct { pthread_t thread; /**< Pthread ID */ pthread_attr_t attr; /**< Pthread attributes */ int core; /**< Core ID */ + /** Saved starting args for join to later free */ + odp_start_args_t *start_args; } odph_linux_pthread_t; diff --git a/platform/linux-generic/odp_linux.c b/platform/linux-generic/odp_linux.c index 229d24e..96d4d5d 100644 --- a/platform/linux-generic/odp_linux.c +++ b/platform/linux-generic/odp_linux.c @@ -26,13 +26,6 @@ #include -typedef struct { - void *(*start_routine) (void *); - void *arg; - -} odp_start_args_t; - - static void *odp_run_start_routine(void *arg) { odp_start_args_t *start_args = arg; @@ -61,7 +54,6 @@ void odph_linux_pthread_create(odph_linux_pthread_t *thread_tbl, int num, { int i; cpu_set_t cpu_set; - odp_start_args_t *start_args; int core_count; int cpu; @@ -83,16 +75,15 @@ void odph_linux_pthread_create(odph_linux_pthread_t *thread_tbl, int num, pthread_attr_setaffinity_np(&thread_tbl[i].attr, sizeof(cpu_set_t), &cpu_set); - start_args = malloc(sizeof(odp_start_args_t)); - if (start_args == NULL) + thread_tbl[i].start_args = malloc(sizeof(odp_start_args_t)); + if (thread_tbl[i].start_args == NULL) ODP_ABORT("Malloc failed"); - memset(start_args, 0, sizeof(odp_start_args_t)); - start_args->start_routine = start_routine; - start_args->arg = arg; + thread_tbl[i].start_args->start_routine = start_routine; + thread_tbl[i].start_args->arg = arg; pthread_create(&thread_tbl[i].thread, &thread_tbl[i].attr, - odp_run_start_routine, start_args); + odp_run_start_routine, thread_tbl[i].start_args); } } @@ -104,7 +95,9 @@ void odph_linux_pthread_join(odph_linux_pthread_t *thread_tbl, int num) for (i = 0; i < num; i++) { /* Wait thread to exit */ pthread_join(thread_tbl[i].thread, NULL); + free(thread_tbl[i].start_args); } + }