tests: Unregister a destructor on leaving a test function
commit65b784bc14014a5c120e76c73ec5c0362d053510
authorPetr Písař <petr.pisar@atlas.cz>
Sun, 30 Jan 2022 09:38:15 +0000 (30 10:38 +0100)
committerPetr Písař <petr.pisar@atlas.cz>
Sun, 30 Jan 2022 09:38:15 +0000 (30 10:38 +0100)
tree47f72b5afe40b349c084e0df4cc4fc9cf1fc6e45
parente61d1504456b80121837acb23549bf630c0a19df
tests: Unregister a destructor on leaving a test function

GCC 12 started to warn on a global variable pointing to a local variable
after getting out of scope of the local variable:

gcc -DHAVE_CONFIG_H -I. -I../..  -I../../src -I../../src -DSRCDIR=\"../..\" -I/usr/include/libxml2 -DLOCALEDIR=\"/usr/share/locale\"   -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -Werror -std=c99 -Wall -c -o isds_PersonName_duplicate.o isds_PersonName_duplicate.c
In file included from isds_PersonName_duplicate.c:1:
isds_PersonName_duplicate.c: In function ‘test_isds_PersonName_duplicate’:
../test.h:39:30: error: storing the address of local variable ‘copy’ in ‘test_destructor_argument’ [-Werror=dangling-pointer=]
   39 |     test_destructor_argument = argument; \
isds_PersonName_duplicate.c:6:29: note: ‘copy’ declared here
    6 |     struct isds_PersonName *copy = isds_PersonName_duplicate(origin);
      |                             ^~~~
../test.h:21:14: note: ‘test_destructor_argument’ declared here
   21 | extern void *test_destructor_argument;
      |              ^~~~~~~~~~~~~~~~~~~~~~~~
test/test.h