From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by dpdk.org (Postfix) with ESMTP id B094FA48A for ; Tue, 17 Apr 2018 11:44:08 +0200 (CEST) Received: by mail-wr0-f193.google.com with SMTP id q13so30212148wre.3 for ; Tue, 17 Apr 2018 02:44:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=VXye6qlXZr7MH19mdE8xjFpFP8Bjup77IquXcCnTKEE=; b=qlkdK77g3fZs5m4f/gv4aDSdjFY8Gp9twE9LUke0mgA7Auj+N6hey3A0vu3wNMerzx wVXSAJTZ21LzFomj3wVvxdLr5N9pzf8mPoQq+KJmQta8ZZsjM+ygD5Ry61bcGu9PRtU5 KXcYCsnNLgHw8fG7sOw/VxBnsmtOmAGkJzrOwEisKA3Df8eQrLLtfZiUSEL3vpHXhSuY 8UfJDlldh76hzm850tRS/31b/u9jKuNcfbwHkle5aZLyH3TZuONa0YNnPqOVLQv0vtLu 9EPCya3vL7mdRU7gog+SV2fnTVfJSQrfv8PjZZ7Rxg4V2J9rh30crp6BCDzCS9ztu1uW 2XaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=VXye6qlXZr7MH19mdE8xjFpFP8Bjup77IquXcCnTKEE=; b=Im9ToUwlw2sg69CAGZ2+KEYDcYLF0u8JD9AVkTAO5/CBAGwFZ3TRlQpwBII7gXfOfl UgMtOyKqevjrGc5j1Tv4Qd6wojAca8cZnSN3nIZGFhbqKyO7STJ5+80tlLJETYCAiRUi ANbScRLnXFczCDlLW7+2yWRnRDOBCZ1m6CerqMVnH1pldhqmslK7G7CGCoDuOhHE3aSc VAZ9FwXfzQbEwTMiKVK3mtlK1uI6fAMGsxGY+djp+M4FHJGRUf0leHxYzq2DHflNpfAn b12f5ktmn1rzot+lxK4EI8IsB9mQS9Sas7EsuKYWvNymQ9LI8dAO/g/MBqzk9nJKQH5M gNRg== X-Gm-Message-State: ALQs6tC5uoPTRNuYdqNknaIvcMxWqu/Qw7vQ20mF5W7kpkS6W0IAGFPS ujloKafz4tUKfS0mJyYMv1BEEDU7 X-Google-Smtp-Source: AIpwx49pdzxvdqduuv5egmbjiy7XaV3UA6lC/T+AJlsHKomH29tE7wBOhAr+xVgKCDn7LXV/3QWCNw== X-Received: by 10.28.91.203 with SMTP id p194mr486809wmb.52.1523958248094; Tue, 17 Apr 2018 02:44:08 -0700 (PDT) Received: from localhost.localdomain (176.122.150.126.16clouds.com. [176.122.150.126]) by smtp.gmail.com with ESMTPSA id p128sm17710718wmd.45.2018.04.17.02.44.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Apr 2018 02:44:07 -0700 (PDT) From: Yangchao Zhou To: dev@dpdk.org Cc: thomas@monjalon.net Date: Tue, 17 Apr 2018 17:43:16 +0800 Message-Id: <1523958196-6408-1-git-send-email-zhouyates@gmail.com> X-Mailer: git-send-email 1.7.1 Subject: [dpdk-dev] [PATCH] mem: memory leaks of hubedir caused by strdup X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Apr 2018 09:44:08 -0000 Fixes: cb97d93e9d3bb5607681085d20acaca1aa16deb1("mem: share hugepage info primary and secondary") Signed-off-by: Yangchao Zhou --- lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 18 +++++++++--------- 1 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c index fb4b667..bf55334 100644 --- a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c +++ b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c @@ -169,8 +169,8 @@ return size; } -static const char * -get_hugepage_dir(uint64_t hugepage_sz) +static int +get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len) { enum proc_mount_fieldnames { DEVICE = 0, @@ -188,7 +188,7 @@ const char split_tok = ' '; char *splitstr[_FIELDNAME_MAX]; char buf[BUFSIZ]; - char *retval = NULL; + int retval = -1; FILE *fd = fopen(proc_mounts, "r"); if (fd == NULL) @@ -215,7 +215,8 @@ /* if no explicit page size, the default page size is compared */ if (pagesz_str == NULL){ if (hugepage_sz == default_size){ - retval = strdup(splitstr[MOUNTPT]); + snprintf(hugedir, len, "%s", splitstr[MOUNTPT]); + retval = 0; break; } } @@ -223,7 +224,8 @@ else { uint64_t pagesz = rte_str_to_size(&pagesz_str[pagesize_opt_len]); if (pagesz == hugepage_sz) { - retval = strdup(splitstr[MOUNTPT]); + snprintf(hugedir, len, "%s", splitstr[MOUNTPT]); + retval = 0; break; } } @@ -351,7 +353,6 @@ for (dirent = readdir(dir); dirent != NULL; dirent = readdir(dir)) { struct hugepage_info *hpi; - const char *hugedir; if (strncmp(dirent->d_name, dirent_start_text, dirent_start_len) != 0) @@ -363,10 +364,10 @@ hpi = &internal_config.hugepage_info[num_sizes]; hpi->hugepage_sz = rte_str_to_size(&dirent->d_name[dirent_start_len]); - hugedir = get_hugepage_dir(hpi->hugepage_sz); /* first, check if we have a mountpoint */ - if (hugedir == NULL) { + if (get_hugepage_dir(hpi->hugepage_sz, + hpi->hugedir, sizeof(hpi->hugedir)) < 0) { uint32_t num_pages; num_pages = get_num_hugepages(dirent->d_name); @@ -378,7 +379,6 @@ num_pages, hpi->hugepage_sz); continue; } - snprintf(hpi->hugedir, sizeof(hpi->hugedir), "%s", hugedir); /* try to obtain a writelock */ hpi->lock_descriptor = open(hpi->hugedir, O_RDONLY); -- 1.7.1