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 CA0EAA0C42; Wed, 23 Jun 2021 20:06:52 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3B4114113A; Wed, 23 Jun 2021 20:06:52 +0200 (CEST) Received: from mail-ot1-f98.google.com (mail-ot1-f98.google.com [209.85.210.98]) by mails.dpdk.org (Postfix) with ESMTP id 7636840141 for ; Wed, 23 Jun 2021 20:06:50 +0200 (CEST) Received: by mail-ot1-f98.google.com with SMTP id d21-20020a9d72d50000b02904604cda7e66so1049252otk.7 for ; Wed, 23 Jun 2021 11:06:50 -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=SHoRAxBAZhG0M3hI87eAwV8ZDlA4blqkKR0vALL6J2k=; b=Wzv+vche3gL0PPIa7ajVaslQ1wh/ktrbFtC6IBRaMsa076x/lRjxXiysDAy1ozXojY IgmfJciLm7oeKqgWYan0l6HJH/jtf2lCe/3CJF/3toXhbaRSyGXgwud6B6TM9zxsDIMh iutmWgxoFkOW+iHFldg28ygEUg6sawqoB7P9g= 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=SHoRAxBAZhG0M3hI87eAwV8ZDlA4blqkKR0vALL6J2k=; b=RyAOP99nZfeX0Mev176CCfvJ4EPuNwnjGxxeVe9OdLB+yKAh6PbrW0x4iAvHrQpJHP qv8Dy6nCw+tZrv3TjYIGSBJbGPwaXvACEElSGE+T6pCXUpC/9vZ+ulOBMKSOLfwGHdIO 3b1pwSndnSTWiGkpbxN1RRFKQLHWjEj9YFXVtor3Ons666W/bqlYEAEt2E8w8wPV9lv1 wAG5ESBb3KlPiLvJN+BftnA/7P8ohvt4sOz1uffRToXNcag37G6uHZ1KQ1Vk9gXWtmz3 4/8gCZcmhtCsqwJDuvKQtXZpd3i8/Vcqe9LstChhHdTexlqYB6ug3yFhcIFr1wQyi4HB vQgg== X-Gm-Message-State: AOAM531+FXodoQA9h3CWql8tJCP0ZTJYyiYcxKvi0zklqNU69fDoRIe1 aKs2ZaKbhGKearLNTXNgvMPlKyQeDDgDaehoeDXq0BNA9gTVh46Ac9jNHVWyVX8CHQ== X-Google-Smtp-Source: ABdhPJw1rOUjy2hChPh+AiVjE+lrnD1fbwcW7GYS656tETeNohAuy3JRIk1ailYN7M0DVa1mdGrj5jnQODjn X-Received: by 2002:a9d:4d9a:: with SMTP id u26mr993012otk.301.1624471609889; Wed, 23 Jun 2021 11:06:49 -0700 (PDT) Received: from postal.iol.unh.edu (postal.iol.unh.edu. [2606:4100:3880:1234::84]) by smtp-relay.gmail.com with ESMTPS id c33sm192337otu.2.2021.06.23.11.06.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jun 2021 11:06:49 -0700 (PDT) X-Relaying-Domain: iol.unh.edu Received: from iol.unh.edu (unknown [IPv6:2606:4100:3880:1220:47d3:d45d:6a1c:8da0]) by postal.iol.unh.edu (Postfix) with ESMTP id 5C4CE6052490; Wed, 23 Jun 2021 14:06:49 -0400 (EDT) From: ohilyard@iol.unh.edu To: olivier.matz@6wind.com Cc: dev@dpdk.org, stable@dpdk.org, david.marchand@redhat.com, Owen Hilyard Date: Wed, 23 Jun 2021 14:06:45 -0400 Message-Id: <20210623180645.91942-1-ohilyard@iol.unh.edu> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210616180724.355217-1-ohilyard@iol.unh.edu> References: <20210616180724.355217-1-ohilyard@iol.unh.edu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v3] tests/cmdline: fix memory leaks X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Owen Hilyard 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 | 40 ++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/app/test/test_cmdline_lib.c b/app/test/test_cmdline_lib.c index bd72df0da..b476b2594 100644 --- a/app/test/test_cmdline_lib.c +++ b/app/test/test_cmdline_lib.c @@ -71,10 +71,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; } @@ -140,32 +142,44 @@ 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; } @@ -176,13 +190,14 @@ test_cmdline_fns(void) struct cmdline *cl; memset(&ctx, 0, sizeof(ctx)); - cl = cmdline_new(&ctx, "test", -1, -1); - if (cl == NULL) + cl = cmdline_new(NULL, "prompt", 0, 0); + if (cl != NULL) goto error; - - if (cmdline_new(NULL, "prompt", 0, 0) != NULL) + cl = cmdline_new(&ctx, NULL, 0, 0); + if (cl != NULL) goto error; - if (cmdline_new(&ctx, NULL, 0, 0) != NULL) + cl = cmdline_new(&ctx, "test", -1, -1); + if (cl == NULL) goto error; if (cmdline_in(NULL, "buffer", CMDLINE_TEST_BUFSIZE) >= 0) goto error; @@ -198,6 +213,7 @@ test_cmdline_fns(void) cmdline_interact(NULL); cmdline_quit(NULL); + cmdline_free(cl); return 0; error: -- 2.30.2