From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DAA4AA0C4D for ; Mon, 16 Aug 2021 14:05:20 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AA0024003C; Mon, 16 Aug 2021 14:05:20 +0200 (CEST) Received: from mail-pl1-f228.google.com (mail-pl1-f228.google.com [209.85.214.228]) by mails.dpdk.org (Postfix) with ESMTP id 7C13E4003C for ; Mon, 16 Aug 2021 14:05:19 +0200 (CEST) Received: by mail-pl1-f228.google.com with SMTP id l11so20465411plk.6 for ; Mon, 16 Aug 2021 05:05:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YDXSsMw/Nnp5HAzL0e7UVplKiNMWOCw8b02UDz5biT8=; b=ZvZ29ycBV9Pprk5lxpvFuAca13Gp7WvfuC8dgk7GChCVcTzxhuTZdhyLfVLvROzLGW 3Vek+KM2wX1C0egNEjuAZJf60irMx6FMUO8P4b2YtI1ZDPq0OWuu3oangKQXtuQHOE47 QysDrzsKX7Iqhd3mpXCgWusbUDFR28I0HCWw8= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=YDXSsMw/Nnp5HAzL0e7UVplKiNMWOCw8b02UDz5biT8=; b=ehZVyZ+9uDtg4zJ2jPi5ElWFw/0z1PoGm5MNz9tsXDvuXrHyVOMpYfATCNNz42kFLu S6SgJr4MKl0X5mf0onqV+hsHdEx/aPDoPz+RuuMIAYeE1qVg9zxsJItBqXqgbeM45+xz N/7Oo/B95oUDtxQiNE+ryGSKW+XLrTOOn+DRLC1ePOuolV4w3lApgfZzyTIqguE49U0R hf1Tinq2+eoI1Ddevhlqwd711hFkwCZ5zrc/bfyW7iM54Pq7wXumtiFpZoH7/7XYmGzv t0oGHjqUuKJQ4hpr3PcZyazj0OV0W8+c1N9IvB80mVuj53CP02MNYxs2Dpc4SpcH9c1k ZqtQ== X-Gm-Message-State: AOAM533VygzvfgSvVEWrCJc8L5SAfwW/1mmwa4yJxPaxJRHM5Snab0Pl JVfjxR5yntCjBATJe+4jeKIZ4z0pBfxkmRibVXQ2o58S/ryubQ== X-Google-Smtp-Source: ABdhPJxYKvCAJqYoSEApAz2HDrZYCf3Y/ODWVJPu9sdVL6oRGkIIBDaAqFp+Z4SQplc8LX4FtfO5RSSu+bwb X-Received: by 2002:a62:d085:0:b0:3e0:f21a:8030 with SMTP id p127-20020a62d085000000b003e0f21a8030mr16293935pfg.70.1629115518649; Mon, 16 Aug 2021 05:05:18 -0700 (PDT) Received: from postal.iol.unh.edu (postal.iol.unh.edu. [132.177.123.84]) by smtp-relay.gmail.com with ESMTPS id oo15sm1630080pjb.17.2021.08.16.05.05.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Aug 2021 05:05:18 -0700 (PDT) X-Relaying-Domain: iol.unh.edu Received: from iol.unh.edu (unknown [IPv6:2606:4100:3880:1220:6ede:a29f:85bd:998f]) by postal.iol.unh.edu (Postfix) with ESMTP id D19AD605248B; Mon, 16 Aug 2021 08:05:17 -0400 (EDT) From: ohilyard@iol.unh.edu To: stable@dpdk.org Cc: christian.ehrhardt@canonical.com, Owen Hilyard , David Marchand Date: Mon, 16 Aug 2021 08:05:13 -0400 Message-Id: <20210816120512.12224-1-ohilyard@iol.unh.edu> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] [PATCH] tests/cmdline: fix memory leaks X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" From: Owen Hilyard [ upstream commit ca7204b921c2f328ab1222772af40922970e7c4b ] Fixes for a few memory leaks in the cmdline_autotest unit test. All of the leaks were related to not freeing the commandline struct after testing had completed. Fixes: dbb860e03e ("cmdline: tests") Signed-off-by: Owen Hilyard Reviewed-by: David Marchand --- app/test/test_cmdline_lib.c | 47 +++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/app/test/test_cmdline_lib.c b/app/test/test_cmdline_lib.c index a856a9713..7d9009408 100644 --- a/app/test/test_cmdline_lib.c +++ b/app/test/test_cmdline_lib.c @@ -62,10 +62,12 @@ test_cmdline_parse_fns(void) if (cmdline_complete(&cl, "buffer", &i, NULL, sizeof(dst)) >= 0) goto error; + cmdline_free(&cl); return 0; error: printf("Error: function accepted null parameter!\n"); + cmdline_free(&cl); return -1; } @@ -131,32 +133,43 @@ static int test_cmdline_socket_fns(void) { cmdline_parse_ctx_t ctx; + struct cmdline* cl; - if (cmdline_stdin_new(NULL, "prompt") != NULL) + cl = cmdline_stdin_new(NULL, "prompt"); + if (cl != NULL) goto error; - if (cmdline_stdin_new(&ctx, NULL) != NULL) + cl = cmdline_stdin_new(&ctx, NULL); + if (cl != NULL) goto error; - if (cmdline_file_new(NULL, "prompt", "/dev/null") != NULL) + cl = cmdline_file_new(NULL, "prompt", "/dev/null"); + if (cl != NULL) goto error; - if (cmdline_file_new(&ctx, NULL, "/dev/null") != NULL) + cl = cmdline_file_new(&ctx, NULL, "/dev/null"); + if (cl != NULL) goto error; - if (cmdline_file_new(&ctx, "prompt", NULL) != NULL) + cl = cmdline_file_new(&ctx, "prompt", NULL); + if (cl != NULL) goto error; - if (cmdline_file_new(&ctx, "prompt", "-/invalid/~/path") != NULL) { + cl = cmdline_file_new(&ctx, "prompt", "-/invalid/~/path"); + if (cl != NULL) { printf("Error: succeeded in opening invalid file for reading!"); + cmdline_free(cl); return -1; } - if (cmdline_file_new(&ctx, "prompt", "/dev/null") == NULL) { + cl = cmdline_file_new(&ctx, "prompt", "/dev/null"); + if (cl == NULL) { printf("Error: failed to open /dev/null for reading!"); + cmdline_free(cl); return -1; } /* void functions */ cmdline_stdin_exit(NULL); - + cmdline_free(cl); return 0; error: printf("Error: function accepted null parameter!\n"); + cmdline_free(cl); return -1; } @@ -164,16 +177,20 @@ static int test_cmdline_fns(void) { cmdline_parse_ctx_t ctx; - struct cmdline cl, *tmp; + struct cmdline cl, *tmp, *tmp2; memset(&ctx, 0, sizeof(ctx)); tmp = cmdline_new(&ctx, "test", -1, -1); - if (tmp == NULL) + if (tmp == NULL) { + tmp2 = NULL; goto error; + } - if (cmdline_new(NULL, "prompt", 0, 0) != NULL) + tmp2 = cmdline_new(NULL, "prompt", 0, 0); + if (tmp2 != NULL) goto error; - if (cmdline_new(&ctx, NULL, 0, 0) != NULL) + tmp2 = cmdline_new(&ctx, NULL, 0, 0); + if (tmp2 != NULL) goto error; if (cmdline_in(NULL, "buffer", CMDLINE_TEST_BUFSIZE) >= 0) goto error; @@ -202,14 +219,18 @@ test_cmdline_fns(void) if (memcmp(&cl, tmp, sizeof(cl))) goto mismatch; cmdline_free(tmp); - + cmdline_free(tmp2); return 0; error: printf("Error: function accepted null parameter!\n"); + cmdline_free(tmp); + cmdline_free(tmp2); return -1; mismatch: printf("Error: data changed!\n"); + cmdline_free(tmp); + cmdline_free(tmp2); return -1; } -- 2.30.2