Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use statically allocated stack.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sun, 20 Oct 2019 19:29:54 +0000 (21:29 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sun, 20 Oct 2019 20:53:14 +0000 (22:53 +0200)
Avoid memory leak and please static analyzers.

tools/cmake/test_prog/prog_makecontext.c

index 37393ce..429875e 100644 (file)
@@ -11,6 +11,7 @@
 #include <stdlib.h>
 #include <ucontext.h>
 
+unsigned char *stack[64 * 1024];
 ucontext_t uc_child;
 ucontext_t uc_main;
 
@@ -23,15 +24,11 @@ static void child(void)
 
 int main(int argc, char *argv[])
 {
-  void *stack = malloc(64 * 1024);
-
   /* configure a child user-space context */
-  if (stack == NULL)
-    exit(3);
   if (getcontext(&uc_child) != 0)
     exit(4);
   uc_child.uc_link = NULL;
-  uc_child.uc_stack.ss_sp = (char *) stack + (32 * 1024);
+  uc_child.uc_stack.ss_sp    = stack + (32 * 1024);
   uc_child.uc_stack.ss_size = 32 * 1024;
   uc_child.uc_stack.ss_flags = 0;
   makecontext(&uc_child, child, 0);