[PATCH v2 2/2] test/strsep: add tests for function strsep()
Andre Muezerie
andremue at linux.microsoft.com
Tue Jul 22 18:37:45 CEST 2025
On Tue, Jul 22, 2025 at 04:30:57PM +0200, David Marchand wrote:
> Hello Andre,
>
> On Mon, Jul 21, 2025 at 10:39 PM Andre Muezerie
> <andremue at linux.microsoft.com> wrote:
> > diff --git a/app/test/test_strsep.c b/app/test/test_strsep.c
> > new file mode 100644
> > index 0000000000..19df8f31ee
> > --- /dev/null
> > +++ b/app/test/test_strsep.c
> > @@ -0,0 +1,108 @@
> > +/* SPDX-License-Identifier: BSD-3-Clause
> > + * Copyright (C) 2025 Microsoft Corporation
> > + */
> > +
> > +#include <string.h>
> > +#include <rte_os_shim.h>
> > +
> > +#include "test.h"
> > +
> > +static int
> > +test_strsep_helper(const char *str, const char *delim,
> > + const char * const expected_tokens[], size_t expected_tokens_count)
> > +{
> > + char *s = str != NULL ? strdup(str) : NULL;
> > + const char *token;
> > + for (size_t i = 0; i < expected_tokens_count; i++) {
> > + token = strsep(&s, delim);
>
> The reference to the dupped string gets lost, since calling strsep updates s.
> Caught by ASan:
>
> ==49990==ERROR: LeakSanitizer: detected memory leaks
>
> Direct leak of 51 byte(s) in 4 object(s) allocated from:
> #0 0x5632dd8cbe83 in strdup
> (/home/runner/work/dpdk/dpdk/build/app/dpdk-test+0x271e83) (BuildId:
> 01a7571ab7814bc83923733b3dae34d28e6ff3e1)
> #1 0x5632de39bad2 in test_strsep_helper
> /home/runner/work/dpdk/dpdk/build/../app/test/test_strsep.c:14:26
> #2 0x5632dd91d86f in unit_test_suite_runner
> /home/runner/work/dpdk/dpdk/build/../app/test/test.c:364:20
> #3 0x5632dd91c2b0 in cmd_autotest_parsed
> /home/runner/work/dpdk/dpdk/build/../app/test/commands.c:68:10
> #4 0x7fba8b3bfc58 in __cmdline_parse
> /home/runner/work/dpdk/dpdk/build/../lib/cmdline/cmdline_parse.c:296:3
> #5 0x7fba8b3bfc58 in cmdline_parse
> /home/runner/work/dpdk/dpdk/build/../lib/cmdline/cmdline_parse.c:305:9
> #6 0x7fba8b3bcbf7 in cmdline_valid_buffer
> /home/runner/work/dpdk/dpdk/build/../lib/cmdline/cmdline.c:25:8
> #7 0x7fba8b3c50ec in rdline_char_in
> /home/runner/work/dpdk/dpdk/build/../lib/cmdline/cmdline_rdline.c:456:5
> #8 0x7fba8b3bcfde in cmdline_in
> /home/runner/work/dpdk/dpdk/build/../lib/cmdline/cmdline.c:154:9
> #9 0x5632dd91d2ba in main
> /home/runner/work/dpdk/dpdk/build/../app/test/test.c:231:15
> #10 0x7fba89a29d8f in __libc_start_call_main
> csu/../sysdeps/nptl/libc_start_call_main.h:58:16
>
> SUMMARY: AddressSanitizer: 51 byte(s) leaked in 4 allocation(s).
> ------------------------------------------------------------------------------
>
>
> --
> David Marchand
Thanks for sending this info. I'll send out a fixed version.
More information about the dev
mailing list