]> sourceware.org Git - systemtap.git/commitdiff
runtime: Make sure to free special message buffers too
authorJosh Stone <jistone@redhat.com>
Fri, 13 Jun 2014 23:12:34 +0000 (16:12 -0700)
committerJosh Stone <jistone@redhat.com>
Fri, 13 Jun 2014 23:15:38 +0000 (16:15 -0700)
These special buffers were formerly kept aside, and never released back
to the memory pool, so they weren't freed either.  DEBUG_MEM did report
this leak properly.  Now these are freed too, and a new debug_mem.exp
test ensures that a simple script doesn't leak any memory.

runtime/transport/control.c
testsuite/systemtap.base/debug_mem.exp [new file with mode: 0644]
testsuite/systemtap.base/debug_mem.stp [new file with mode: 0644]

index 4b9975144b75a8f2ea983c6f7be9f4157354e45d..4151a93cd7b36a6ace1a11afd3d289bb95267bc8 100644 (file)
@@ -298,6 +298,52 @@ static int _stp_ctl_alloc_special_buffers(void)
 }
 
 
+/* Free the buffers for all "special" message types, plus generic
+   warning and error messages.  */
+static void _stp_ctl_free_special_buffers(void)
+{
+       if (_stp_ctl_start_msg != NULL) {
+               _stp_mempool_free(_stp_ctl_start_msg);
+               _stp_ctl_start_msg = NULL;
+       }
+
+       if (_stp_ctl_exit_msg != NULL) {
+               _stp_mempool_free(_stp_ctl_exit_msg);
+               _stp_ctl_exit_msg = NULL;
+       }
+
+       if (_stp_ctl_transport_msg != NULL) {
+               _stp_mempool_free(_stp_ctl_transport_msg);
+               _stp_ctl_transport_msg = NULL;
+       }
+
+       if (_stp_ctl_request_exit_msg != NULL) {
+               _stp_mempool_free(_stp_ctl_request_exit_msg);
+               _stp_ctl_request_exit_msg = NULL;
+       }
+
+       if (_stp_ctl_oob_warn != NULL) {
+               _stp_mempool_free(_stp_ctl_oob_warn);
+               _stp_ctl_oob_warn = NULL;
+       }
+
+       if (_stp_ctl_oob_err != NULL) {
+               _stp_mempool_free(_stp_ctl_oob_err);
+               _stp_ctl_oob_err = NULL;
+       }
+
+       if (_stp_ctl_system_warn != NULL) {
+               _stp_mempool_free(_stp_ctl_system_warn);
+               _stp_ctl_system_warn = NULL;
+       }
+
+       if (_stp_ctl_realtime_err != NULL) {
+               _stp_mempool_free(_stp_ctl_realtime_err);
+               _stp_ctl_realtime_err = NULL;
+       }
+}
+
+
 /* Get a buffer based on type, possibly a generic buffer, when all else
    fails returns NULL and there is nothing we can do.  */
 static struct _stp_buffer *_stp_ctl_get_buffer(int type, void *data,
@@ -631,14 +677,15 @@ err0:
 
 static void _stp_unregister_ctl_channel(void)
 {
-       struct list_head *p, *tmp;
+       struct _stp_buffer *bptr, *tmp;
 
        _stp_unregister_ctl_channel_fs();
 
        /* Return memory to pool and free it. */
-       list_for_each_safe(p, tmp, &_stp_ctl_ready_q) {
-               list_del(p);
-               _stp_mempool_free(p);
+       list_for_each_entry_safe(bptr, tmp, &_stp_ctl_ready_q, list) {
+               list_del(&bptr->list);
+               _stp_ctl_free_buffer(bptr);
        }
+       _stp_ctl_free_special_buffers();
        _stp_mempool_destroy(_stp_pool_q);
 }
diff --git a/testsuite/systemtap.base/debug_mem.exp b/testsuite/systemtap.base/debug_mem.exp
new file mode 100644 (file)
index 0000000..e11eb60
--- /dev/null
@@ -0,0 +1,31 @@
+set test debug_mem
+set script "$srcdir/$subdir/$test.stp"
+
+if {![installtest_p]} { untested $test; return }
+
+if { [catch {exec stap -g -DDEBUG_MEM=1 "$script"} out] } {
+    fail "$test (run)"
+    return
+} else {
+    pass "$test (run)"
+}
+
+set errors 0
+spawn dmesg
+expect {
+    -timeout 60
+    -re {SYSTEMTAP DEBUG_MEM TEST\r\n} { set errors 0; exp_continue }
+    -re {SYSTEMTAP ERROR:[^\r\n]+\r\n} { incr errors; exp_continue }
+    -re {^[^\r\n]+\r\n} {
+       # ignore output we're not interested in
+       exp_continue }
+    timeout { verbose -log "TIMEOUT" }
+}
+catch { close }
+catch { wait }
+
+if { $errors == 0 } {
+    pass "$test"
+} else {
+    fail "$test ($errors)"
+}
diff --git a/testsuite/systemtap.base/debug_mem.stp b/testsuite/systemtap.base/debug_mem.stp
new file mode 100644 (file)
index 0000000..0db39a7
--- /dev/null
@@ -0,0 +1,6 @@
+probe begin {
+       // printk a line so we can look for DEBUG_MEM errors after it
+       printk(7, "SYSTEMTAP DEBUG_MEM TEST")
+       exit()
+}
+
This page took 0.030284 seconds and 5 git commands to generate.