From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BC907385AE69; Thu, 9 Jun 2022 09:33:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC907385AE69 From: "contino at epigenesys dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/105906] New: fanalyzer strdup false positive leak in loop Date: Thu, 09 Jun 2022 09:33:01 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: analyzer X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: contino at epigenesys dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: dmalcolm at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Jun 2022 09:33:01 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105906 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=3D53109&action=3Dedit The warning Hi, compiling the code with GCC-12.1.0 on Debian I am seeing the fanalyzer warn= ing in the attachment, which seems to me a false positive leak related to strdu= p. Code: #include #include #include #define LEN 64 char **__epystr_explode(const char *delim, char *str) { char **out =3D NULL; int i; if (str =3D=3D NULL || delim =3D=3D NULL) return NULL; out =3D malloc(LEN * sizeof(char *)); if (out =3D=3D NULL) return NULL; for (i =3D 0; i < LEN; i++) { out[i] =3D strdup("bla"); if (out[i] =3D=3D NULL) goto freem; } return out; freem: while (--i >=3D 0) free(out[i]); free(out); return NULL; } If I replace strdup with malloc the warning disappears. for (i =3D 0; i < LEN; i++) { out[i] =3D malloc(10); if (out[i] =3D=3D NULL) goto freem; } The same happens if I replace the for loop with a goto loop. i =3D 0; loop: out[i] =3D strdup("bla"); if (out[i] =3D=3D NULL) goto freem; i++ if (i < LEN) goto loop;=