Skip to contentSkip to conversation

rt-tests: cyclicdeadline: fix segmentation fault on close

PATCH In review Kurt Kanzenbach 2 participants 2 messages Apr 4, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rt-tests: cyclicdeadline: fix segmentation fault on close

The setcpu_buf is unconditionally freed at the end of the program. However, there are code paths in which it is not allocated:

  $ sudo ./cyclicdeadline
  Using all CPUS
  /sys/kernel/debug/sched_features: Success
  interval: 600:1000
    Tested at 5us of 600us
  deadline thread 2963
  thread[2963] runtime=600us deadline=1000us
  main thread 2962
  fail 2 0
  T: 0 ( 2963) I:1000 C:   1268 Min:      7 Act:   55 Avg:   56 Max:     256
  [1]    2961 segmentation fault  sudo ./cyclicdeadline

Fix it by adding the NULL check.

---
 src/sched_deadline/cyclicdeadline.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/sched_deadline/cyclicdeadline.c +2 -1
index 08460107c464..614ad54c171f 100644
@@ -1261,6 +1261,7 @@ int main (int argc, char **argv)
 		}
 	}
 
-	free(setcpu_buf);
+	if (setcpu_buf)
+		free(setcpu_buf);
 	return 0;
 }
Signature · 1 line
2.11.0
#1 lore raw

Hi,

Quoted 15 lines · Kurt Kanzenbach

The setcpu_buf is unconditionally freed at the end of the program. However, there are code paths in which it is not allocated:

  $ sudo ./cyclicdeadline
  Using all CPUS
  /sys/kernel/debug/sched_features: Success
  interval: 600:1000
    Tested at 5us of 600us
  deadline thread 2963
  thread[2963] runtime=600us deadline=1000us
  main thread 2962
  fail 2 0
  T: 0 ( 2963) I:1000 C:   1268 Min:      7 Act:   55 Avg:   56 Max:     256
  [1]    2961 segmentation fault  sudo ./cyclicdeadline
Quoted 1 line

Fix it by adding the NULL check.

free(3) is actually NULL safe. So, that's not the problem. We're debugging it.

Thanks,
Kurt