public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-5757] analyzer: add regression test for leak false +ve [PR103526]
@ 2021-12-02 19:05 David Malcolm
  0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2021-12-02 19:05 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:38a0ee2649ef236ea2763bb9cfc42dc917c7d3fd

commit r12-5757-g38a0ee2649ef236ea2763bb9cfc42dc917c7d3fd
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Thu Dec 2 11:48:04 2021 -0500

    analyzer: add regression test for leak false +ve [PR103526]
    
    gcc/testsuite/ChangeLog:
            PR analyzer/103526
            * gcc.dg/analyzer/pr103526.c: New test.
    
    Signed-off-by: David Malcolm <dmalcolm@redhat.com>

Diff:
---
 gcc/testsuite/gcc.dg/analyzer/pr103526.c | 50 ++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/analyzer/pr103526.c b/gcc/testsuite/gcc.dg/analyzer/pr103526.c
new file mode 100644
index 00000000000..39d60fd853e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/pr103526.c
@@ -0,0 +1,50 @@
+#include <stdlib.h>
+#include <string.h>
+
+struct game_state {
+	const char *word;
+	char       *word_state;
+};
+
+const char *const teststr = "test string";
+
+static struct game_state *
+game_new(void)
+{
+	struct game_state tmp = {0};
+	struct game_state *rval = NULL;
+	size_t wordlen;
+
+	tmp.word = teststr;
+	wordlen = strlen(tmp.word);
+	if ((tmp.word_state = malloc(wordlen+1)) == NULL)
+		goto err;
+	if ((rval = malloc(sizeof(*rval))) == NULL)
+		goto err;
+	memcpy(rval, &tmp, sizeof(*rval));
+
+	return (rval);
+err:
+	free(tmp.word_state);
+	free(rval);
+	return (NULL);
+} /* { dg-bogus "leak" } */
+
+static void
+game_free(struct game_state *game)
+{
+	if (game == NULL)
+		return;
+	free(game->word_state);
+	free(game);
+}
+
+int
+main(void)
+{
+	struct game_state *game;
+	if ((game = game_new()) == NULL)
+		exit(1);
+	game_free(game);
+	exit(0);
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-02 19:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-02 19:05 [gcc r12-5757] analyzer: add regression test for leak false +ve [PR103526] David Malcolm

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).