(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
analyzer/
pr103526.c
       1  #include <stdlib.h>
       2  #include <string.h>
       3  
       4  struct game_state {
       5  	const char *word;
       6  	char       *word_state;
       7  };
       8  
       9  const char *const teststr = "test string";
      10  
      11  static struct game_state *
      12  game_new(void)
      13  {
      14  	struct game_state tmp = {0};
      15  	struct game_state *rval = NULL;
      16  	size_t wordlen;
      17  
      18  	tmp.word = teststr;
      19  	wordlen = strlen(tmp.word);
      20  	if ((tmp.word_state = malloc(wordlen+1)) == NULL)
      21  		goto err;
      22  	if ((rval = malloc(sizeof(*rval))) == NULL)
      23  		goto err;
      24  	memcpy(rval, &tmp, sizeof(*rval));
      25  
      26  	return (rval);
      27  err:
      28  	free(tmp.word_state);
      29  	free(rval);
      30  	return (NULL);
      31  } /* { dg-bogus "leak" } */
      32  
      33  static void
      34  game_free(struct game_state *game)
      35  {
      36  	if (game == NULL)
      37  		return;
      38  	free(game->word_state);
      39  	free(game);
      40  }
      41  
      42  int
      43  main(void)
      44  {
      45  	struct game_state *game;
      46  	if ((game = game_new()) == NULL)
      47  		exit(1);
      48  	game_free(game);
      49  	exit(0);
      50  }