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 992BCA0548; Wed, 16 Jun 2021 18:48:41 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 20B714067A; Wed, 16 Jun 2021 18:48:41 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mails.dpdk.org (Postfix) with ESMTP id C793840140 for ; Wed, 16 Jun 2021 18:48:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623862118; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wP+T0O+74nneHIhNxvW7EO9A4YO5ivMWPlLnGx4kpeY=; b=ZtnEF2tV2/2a/fkkt8D/SQ0C7EU/dd6j7qqMCijSqTfzYHslWz/CMJAHG+jjRiqszWJt5K Y1amMqOpa0tDWhxPCVw6rzqT2uDE/6R+OHago2KfLc4m4Tvppqd8Yj8a4W7Z//IHRhGfFX qTNzAvBAIITPppOR+MqkYB7xJruuA9A= Received: from mail-ua1-f69.google.com (mail-ua1-f69.google.com [209.85.222.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-73-eye1nNVfPBCRLWIAf1FAVQ-1; Wed, 16 Jun 2021 12:48:37 -0400 X-MC-Unique: eye1nNVfPBCRLWIAf1FAVQ-1 Received: by mail-ua1-f69.google.com with SMTP id f15-20020a9f2bcf0000b02901f8fe91b89cso1238559uaj.0 for ; Wed, 16 Jun 2021 09:48:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wP+T0O+74nneHIhNxvW7EO9A4YO5ivMWPlLnGx4kpeY=; b=jlIKMj+Q5pNzCge561ayYpHfSXAqdsqTVugDaL7V2c9CSHBQRnMed3+YyoPeHden0/ 6YpmtI+s5z8YCXuMf0wzzO1KLGn6KxKFuc7rJVaJSZZqUkLZEy/FqtVdYFvJGPAbQqTM ftvbs5GE6tI5oZJkxwcOmYfd08T3pjkuhnBsaIHGQrplmw77x1l2HEh222xP3JqbonaA DyZDjle0BXVFaGnrkPvmw0hjAgeZ9XPXPmE9TVtiHLBCLzl/gvvUj9eMcsO/T5P3/eYu iC9XF5AwC92EvnekTSIjyhUD85Lj7PLBDhJA0+IQ5+5Yzpq4deua7u7dxcoT7es852Ow Cyhw== X-Gm-Message-State: AOAM533EJ8jlQKEzeP06C2SOnrwU8kpOppJTDBoH+ulWz7/zzb2SNH7T LtXKvEGdeoUV/IG4+3eIQ6T9igOWQDuMzRNMnyBW3BlkKXNAxaY/8QyEyR4INfS5gGNsgWO4p/G ph303xbOEQiDSRxQQKv8= X-Received: by 2002:a67:d01a:: with SMTP id r26mr1114864vsi.5.1623862117137; Wed, 16 Jun 2021 09:48:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDMkiM4o+hrPuMWZej6SEs0ZIp5q4xZ2e7nSfU16dPbEU0de68HvhCoo3+7MHZGysaZqE4AJ6ld43+uCIzWSw= X-Received: by 2002:a67:d01a:: with SMTP id r26mr1114845vsi.5.1623862116960; Wed, 16 Jun 2021 09:48:36 -0700 (PDT) MIME-Version: 1.0 References: <20210616162553.350074-1-ohilyard@iol.unh.edu> In-Reply-To: <20210616162553.350074-1-ohilyard@iol.unh.edu> From: David Marchand Date: Wed, 16 Jun 2021 18:48:25 +0200 Message-ID: To: Owen Hilyard Cc: Olivier Matz , dev Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dmarchan@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Subject: Re: [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" On Wed, Jun 16, 2021 at 6:26 PM wrote: > > 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. We will need a Fixes: tag and Cc: stable. > > 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); We made sure cl != NULL above, no need for this test. > return 0; > error: > printf("Error: function accepted null parameter!\n"); > + if (cl != NULL) > + cmdline_free(cl); And anyway, cmdline_free() handles a NULL pointer fine, so you can also remove the check here. With commitlog updated and those two changes, you can add my: Reviewed-by: David Marchand > 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 > -- David Marchand