From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ie0-f177.google.com (mail-ie0-f177.google.com [209.85.223.177]) by dpdk.org (Postfix) with ESMTP id 4B944AFD3 for ; Thu, 26 Jun 2014 16:56:01 +0200 (CEST) Received: by mail-ie0-f177.google.com with SMTP id tp5so3134974ieb.36 for ; Thu, 26 Jun 2014 07:56:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=3w4/sYB12kGHknhuIEwq/ptyOm7shzMCtQ+aLZ7q/9Y=; b=UixXff0G1MXjai9slWpgxWxmgRMqKVASGOGEqeLCAN5Gwz7GYQ7QRFUaLmEM7XssJY bIaF9wLvlmc3F3Ki/OjP+wPuZtLBGvz+APz+QhC3blGiB20Ot68+1mCCB0EvKE9F+90H wqvmVwMKv7T6wDS7Oxv0XdTIDARmby3Qci0sNLbRXw43fHf1HpVBmMWppemgO89PPVkT GIo/7F3Q9/lHDNpfjUlswkvm9zBAul1OFWLVCbdjDiiU5Pu0Rt4rux1dusB60IjUK+HM Ne83Z270FIUTAsRfMSYt2KZ7tIQ31sHV8ebDhk/gSXqnkk/t+N70AggkAawE7FUaSWQK PGUw== X-Gm-Message-State: ALoCoQlbkJAaV0ScZgTowvY7zXbxTFZreqAKauI4EZCZkvsRidfdCHW5bUhBNOLpVGSDo4GSEq4U X-Received: by 10.42.85.81 with SMTP id p17mr14413373icl.33.1403794579532; Thu, 26 Jun 2014 07:56:19 -0700 (PDT) Received: from arch-vtune.arbor.net ([216.130.192.3]) by mx.google.com with ESMTPSA id y15sm4887414igy.2.2014.06.26.07.56.18 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 26 Jun 2014 07:56:18 -0700 (PDT) From: Aaron Campbell To: dev@dpdk.org Date: Thu, 26 Jun 2014 10:54:34 -0400 Message-Id: <1403794474-17695-1-git-send-email-aaron@arbor.net> X-Mailer: git-send-email 1.8.3.2 Subject: [dpdk-dev] [PATCH] eal: fix invalid memory read as reported by valgrind X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Jun 2014 14:56:01 -0000 ==29880== Invalid read of size 1 ==29880== at 0x56FF9A5: cpu_socket_id (eal_lcore.c:101) ==29880== by 0x56FFAE9: rte_eal_cpu_init (eal_lcore.c:168) ==29880== by 0x56F944A: rte_eal_init (eal.c:975) The problem is that endptr points to memory allocated underneath the DIR handle, which has already been freed. So move the closedir() call lower. Signed-off-by: Aaron Campbell --- lib/librte_eal/linuxapp/eal/eal_lcore.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_lcore.c b/lib/librte_eal/linuxapp/eal/eal_lcore.c index cc9b900..fd11142 100644 --- a/lib/librte_eal/linuxapp/eal/eal_lcore.c +++ b/lib/librte_eal/linuxapp/eal/eal_lcore.c @@ -77,7 +77,7 @@ cpu_socket_id(unsigned lcore_id) const char node_prefix[] = "node"; const size_t prefix_len = sizeof(node_prefix) - 1; char path[PATH_MAX]; - DIR *d; + DIR *d = NULL; unsigned long id = 0; struct dirent *e; char *endptr = NULL; @@ -97,7 +97,6 @@ cpu_socket_id(unsigned lcore_id) break; } } - closedir(d); if (endptr == NULL || *endptr!='\0' || endptr == e->d_name+prefix_len) { RTE_LOG(WARNING, EAL, "Cannot read numa node link " "for lcore %u - using physical package id instead\n", @@ -110,9 +109,12 @@ cpu_socket_id(unsigned lcore_id) if (eal_parse_sysfs_value(path, &id) != 0) goto err; } + closedir(d); return (unsigned)id; err: + if (d) + closedir(d); RTE_LOG(ERR, EAL, "Error getting NUMA socket information from %s " "for lcore %u - assuming NUMA socket 0\n", SYS_CPU_DIR, lcore_id); return 0; -- 1.8.3.2