From patchwork Mon Apr 29 07:07:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13646398 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6703C125C7; Mon, 29 Apr 2024 07:07:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714374474; cv=none; b=Qi9L1en4xyGLdNLCtWSgJK2pGJEP/7qka1eCkoLQ4pdMIFJKRrahijB+X88rEwMfujnqWaYkLxE+4COPWCjpK5P3rvHWLtLejZKzXjn/VHmlJ1cZf255nq4LDCyUSNbaRy5I2wn9YcX1XtvFButP1a+VoN1dJM4qxadWhUgyJRI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714374474; c=relaxed/simple; bh=DXr2pMZh7BTOmXSIeZOIVP06BS3XnB4krkOXdDtC3zM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ieHpW4IyHjSoRgUjHKeWi9dmzwQdQ/SnrYB/aayeQ/4kV47W9+1lEGHxx/vxQFS/cJjWQXxfo0Y+1c0uHHcG9sjIC7MUClOwxoyKw2LZqYJMI6M1nu6wm1OR81DEWBz8r8PsPDCSVlIW9oYPlBBDctMT7nNvpNI1vFwKEFRj2Ps= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eLMt7s9g; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eLMt7s9g" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FBF1C4AF1C; Mon, 29 Apr 2024 07:07:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714374474; bh=DXr2pMZh7BTOmXSIeZOIVP06BS3XnB4krkOXdDtC3zM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eLMt7s9gnGcSAg6lUy583TSGw/+8hkYjfuSpyVaSgK/d7yUXKwbJcUFyZSHWKLFo4 OtgGLxWSJnGZPuf0NRLJHYyGz4JM0GU79BgtlkangSEp4MoBqnjcLotKrDOCyekKo8 EOiaeCsLVRFNuEAnoht/HuHFRe2/5/9msQNiSbZC8hrY2+fuPwR50cgQ0cDlzFkJ5v pHY+dSQcSlLe+B6ZMgegNMkGfYff4AImglJyscPF4DSy7GGdY5RLwFONlXN35U1XMf bFjNAcmHUbg2tcesxITDRTX/H5Q2DNskyXew9mQGevw6D+Kl0LC2wSizVr8h5Yw2Pf GONa77GuJRbYA== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Jakub Sitnicki Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, Geliang Tang Subject: [PATCH bpf-next 1/2] selftests/bpf: Free strdup memory in test_sockmap Date: Mon, 29 Apr 2024 15:07:33 +0800 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang The strdup() function returns a pointer to a new string which is a duplicate of the string "ptr". Memory for the new string is obtained with malloc(), and need to be freed with free(). This patch adds these missing "free(ptr)" in check_whitelist() and check_blacklist() to avoid memory leaks in test_sockmap.c. Signed-off-by: Geliang Tang Acked-by: Yonghong Song Acked-by: John Fastabend --- tools/testing/selftests/bpf/test_sockmap.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c index 43612de44fbf..92752f5eeded 100644 --- a/tools/testing/selftests/bpf/test_sockmap.c +++ b/tools/testing/selftests/bpf/test_sockmap.c @@ -1887,10 +1887,13 @@ static int check_whitelist(struct _test *t, struct sockmap_options *opt) while (entry) { if ((opt->prepend && strstr(opt->prepend, entry) != 0) || strstr(opt->map, entry) != 0 || - strstr(t->title, entry) != 0) + strstr(t->title, entry) != 0) { + free(ptr); return 0; + } entry = strtok(NULL, ","); } + free(ptr); return -EINVAL; } @@ -1907,10 +1910,13 @@ static int check_blacklist(struct _test *t, struct sockmap_options *opt) while (entry) { if ((opt->prepend && strstr(opt->prepend, entry) != 0) || strstr(opt->map, entry) != 0 || - strstr(t->title, entry) != 0) + strstr(t->title, entry) != 0) { + free(ptr); return 0; + } entry = strtok(NULL, ","); } + free(ptr); return -EINVAL; }