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 0D46EA0C42 for ; 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 006764003F; Wed, 23 Jun 2021 20:06:52 +0200 (CEST) Received: from mail-ot1-f99.google.com (mail-ot1-f99.google.com [209.85.210.99]) by mails.dpdk.org (Postfix) with ESMTP id 7015A4003F for ; Wed, 23 Jun 2021 20:06:50 +0200 (CEST) Received: by mail-ot1-f99.google.com with SMTP id t4-20020a9d66c40000b029045e885b18deso2827203otm.6 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=doMgkMC0hkXIuNSTMy7OPYAG/astigZZL3zqnAppqd6h7gQ9G81RUQB+XjX97bvkSH K3jp0ux/snLZxMa1dq73FWDZx9AcoZtU01NU+rd9+MMpG3t4dZuCisYBcGQrlBfTWGFf CPP8iS52We5R7K6ms9HHsWfhI+IgY/Lk6pUXFwfT219Oi4SZOixYrKbrAFL1ewo0RsEs tjqv9Xa0ssdueSRIiuN27YJyVxbMxF0ZiuYsimq2vUH+rgkMkFt1HGC88LFIcyJUctv7 1p9PH+PKGuSuVM+6LWfajTcjLtlpsuOUrJ5AlPlMObmtnKjhk41GVagnq6i+m5lIUBKS IL2A== X-Gm-Message-State: AOAM531RyRw97TNa50GpW/vyPzpJBirJrRBNq4DskmRLX9LBSP+3d5Ww kazylmpBqVHWVtHEMaNmPcyii6+h2UIkoz4OZrPFa4m+H+4knJxL0mk9v+u2KkB0XA== 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-stable] [PATCH v3] 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 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