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 75219A0548; Wed, 16 Jun 2021 18:25:56 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5EE194067A; Wed, 16 Jun 2021 18:25:56 +0200 (CEST) Received: from mail-vs1-f97.google.com (mail-vs1-f97.google.com [209.85.217.97]) by mails.dpdk.org (Postfix) with ESMTP id 9451140140 for ; Wed, 16 Jun 2021 18:25:55 +0200 (CEST) Received: by mail-vs1-f97.google.com with SMTP id z15so1336254vsn.13 for ; Wed, 16 Jun 2021 09:25:55 -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:mime-version :content-transfer-encoding; bh=/wxqMlQYfU2FClAIKJa/bZVPG9abMN/QANklvgpKx9c=; b=EnQrt5ZLhY/fKzkT8687fpS61xtul5j9SQ2caMC4vYQYUdC8Tf9dmXUFs0qCjO8pxH Lfq5olT04Nzd1h46xKsjrppzQQhGZCkdysU170SMl6VHFt8giOHk4XCR2El/ScpNAlpf 3Ccs3tsbQX5ZGro7cjHbeBbY40/zUHQY4Ch/0= 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:mime-version :content-transfer-encoding; bh=/wxqMlQYfU2FClAIKJa/bZVPG9abMN/QANklvgpKx9c=; b=CsuoM99Ccrv+i2P8sJ8EEMlmuikC9/uuxrefsM0rwZQ5rbnCVjk3qSz2Pwnb+Y1Nyp rjcu0C1Y+1Fd54OMy6rY6uGC+2CkTJsgqNlVwfLOhytc6q/V4FCktLGk7R9HPjQuD6L0 TDXlAlrYrhv5Pab0UtAfCRiKBp52iAfC2/lAVfflbQFIPaD3FfUHq0k9iqpcVEU2/A1f wPJzXWABPAqIvwYG6TOtQtoJb4s9nQLwIcZdcVN1oRRfobMDAQ9s1iIxiC1PPBZ/eRyZ i+NYUsLCqzDiYtzqx3LaRknaIEUhRVqmd8dPX3kyGyKJZjFR/5S+wdS10gRsPvf63a7s 2OFA== X-Gm-Message-State: AOAM532hqaWaw7W6PrM9FtUq40KOzo0HcbJK9QFNLDlzrGTtk4KtLlGy YYs55+o465TL86QJlur+Bo9R11dHd9w//JTguwgvGG90kykph5W8IaWr8P6Hxi4IbA== X-Google-Smtp-Source: ABdhPJy4U180047ApRYfWA1w3De+6u7i4RXcbsNMCogdKCBLgyE5hTHIt5yLrsJWuZX7BXadUkZs+0XsGJp0 X-Received: by 2002:a67:3009:: with SMTP id w9mr971896vsw.50.1623860754991; Wed, 16 Jun 2021 09:25:54 -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 x6sm1103286vsn.2.2021.06.16.09.25.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Jun 2021 09:25:54 -0700 (PDT) X-Relaying-Domain: iol.unh.edu Received: from iol.unh.edu (unknown [IPv6:2606:4100:3880:1220:5e2f:685e:142b:54c3]) by postal.iol.unh.edu (Postfix) with ESMTP id EDC80605246B; Wed, 16 Jun 2021 12:25:53 -0400 (EDT) From: ohilyard@iol.unh.edu To: olivier.matz@6wind.com Cc: dev@dpdk.org, david.marchand@redhat.com, Owen Hilyard Date: Wed, 16 Jun 2021 12:25:52 -0400 Message-Id: <20210616162553.350074-1-ohilyard@iol.unh.edu> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] 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. Signed-off-by: Owen Hilyard --- app/test/test_cmdline_lib.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/app/test/test_cmdline_lib.c b/app/test/test_cmdline_lib.c index bd72df0da..fd0a797c1 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,45 @@ 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); - + if (cl != NULL) + cmdline_free(cl); return 0; error: printf("Error: function accepted null parameter!\n"); + if (cl != NULL) + cmdline_free(cl); return -1; } @@ -198,6 +213,7 @@ test_cmdline_fns(void) cmdline_interact(NULL); cmdline_quit(NULL); + cmdline_free(cl); return 0; error: -- 2.30.2