]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Ensure none/tests/linux/mremap[456].c remove the shared memory
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sun, 23 Nov 2025 15:49:01 +0000 (16:49 +0100)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sun, 23 Nov 2025 15:49:01 +0000 (16:49 +0100)
As otherwise, each execution of a test leaves some shared memory lingering.

Verified by doing:
   ipcs -m | wc
   mremap4
   ipcs -m | wc

and that the nr does not increase after the fix.

none/tests/linux/mremap4.c
none/tests/linux/mremap5.c
none/tests/linux/mremap6.c

index 3fe2307de7a8d5969c062351d736160f6700f494..2328cb812bb1e9404b1e502d0c9ad8407bf30ddb 100644 (file)
@@ -19,5 +19,8 @@ int main()
   addr = mremap(addr, 100 * 4096, 40 * 4096, 0);
   assert(addr != (void *)-1);
 
+  int rmid = shmctl(shmid, IPC_RMID, NULL);
+  assert(rmid == 0);
+
   return 0;
 }
index dcea248d78d5c348fbd4d796c0e3db54ef390d64..e78250aeba92e94ee370c4e9cbda2050e00a6292 100644 (file)
@@ -19,5 +19,8 @@ int main()
   addr = mremap(addr, 100 * 4096, 400 * 4096, MREMAP_MAYMOVE);
   assert(addr != (void *)-1);
 
+  int rmid = shmctl(shmid, IPC_RMID, NULL);
+  assert(rmid == 0);
+
   return 0;
 }
index bcebaf59a2a4f2d59697a68c94c1dd61d1496ce4..44a733b5d6119998f53b932a7b89ff90f9787ac5 100644 (file)
@@ -7,10 +7,12 @@
 #include <sys/stat.h>
 #include <sys/mman.h>
 
+static int shmid;
+
 static void *mkmap(unsigned sz)
 {
-  int shmid = shmget(IPC_PRIVATE, sz, 
-                     IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
+  shmid = shmget(IPC_PRIVATE, sz,
+                 IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
   assert(shmid != -1);
 
   void *addr = shmat(shmid, NULL, 0);
@@ -22,10 +24,13 @@ static void *mkmap(unsigned sz)
 int main()
 {
   void *np, *p;
-       
+
   p  = mkmap(1024*1024);
   np = mremap(p, 1024*1024, 2048*1024, MREMAP_MAYMOVE); /* grow, maymove */
   assert(np != (void *)-1);
 
+  int rmid = shmctl(shmid, IPC_RMID, NULL);
+  assert(rmid == 0);
+
   return 0;
 }