public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/105906] New: fanalyzer strdup false positive leak in loop
@ 2022-06-09  9:33 contino at epigenesys dot com
  2022-06-10 12:19 ` [Bug analyzer/105906] " dmalcolm at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: contino at epigenesys dot com @ 2022-06-09  9:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105906

            Bug ID: 105906
           Summary: fanalyzer strdup false positive leak in loop
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: contino at epigenesys dot com
  Target Milestone: ---

Created attachment 53109
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53109&action=edit
The warning

Hi,
compiling the code with GCC-12.1.0 on Debian I am seeing the fanalyzer warning
in the attachment, which seems to me a false positive leak related to strdup.

Code:

#include <stddef.h>
#include <stdlib.h>
#include <string.h>

#define LEN 64

char **__epystr_explode(const char *delim, char *str)
{
        char **out = NULL;
        int i;

        if (str == NULL || delim == NULL)
                return NULL;

        out = malloc(LEN * sizeof(char *));
        if (out == NULL)
                return NULL;

        for (i = 0; i < LEN; i++) {
                out[i] = strdup("bla");
                if (out[i] == NULL)
                        goto freem;
        }
        return out;

freem:
        while (--i >= 0)
                free(out[i]);
        free(out);
        return NULL;
}

If I replace strdup with malloc the warning disappears.

for (i = 0; i < LEN; i++) {
        out[i] = malloc(10);
        if (out[i] == NULL)
                goto freem;
}

The same happens if I replace the for loop with a goto loop.

i = 0;
loop:
out[i] = strdup("bla");
if (out[i] == NULL)
        goto freem;
i++
if (i < LEN)
        goto loop;

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-03-13 18:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-09  9:33 [Bug analyzer/105906] New: fanalyzer strdup false positive leak in loop contino at epigenesys dot com
2022-06-10 12:19 ` [Bug analyzer/105906] " dmalcolm at gcc dot gnu.org
2023-03-13 18:36 ` dmalcolm at gcc dot gnu.org
2023-03-13 18:37 ` dmalcolm at gcc dot gnu.org
2023-03-13 18:54 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).