<feed xmlns='http://www.w3.org/2005/Atom'>
<title>paraslash/buffer_tree.c, branch pu</title>
<subtitle>paraslash - network audio streaming tools</subtitle>
<id>https://git.tue.mpg.de/cgit/paraslash/atom?h=pu</id>
<link rel='self' href='https://git.tue.mpg.de/cgit/paraslash/atom?h=pu'/>
<link rel='alternate' type='text/html' href='https://git.tue.mpg.de/cgit/paraslash/'/>
<updated>2026-05-08T20:19:58Z</updated>
<entry>
<title>btr: Simplify btr_drop_buffer_reference().</title>
<updated>2026-05-08T20:19:58Z</updated>
<author>
<name>Andre Noll</name>
<email>maan@tuebingen.mpg.de</email>
</author>
<published>2026-03-16T00:54:46Z</published>
<link rel='alternate' type='text/html' href='https://git.tue.mpg.de/cgit/paraslash/commit/?id=0981aa201d36ae40f4e52209faf141fbaa7c4328'/>
<id>urn:sha1:0981aa201d36ae40f4e52209faf141fbaa7c4328</id>
<content type='text'>
Drop the bool flag which indicates whether the buffer itself should also be
deallocated. The function can answer this itself by consulting the dont_free
flag of the buffer pointer.
</content>
</entry>
<entry>
<title>Switch to SPDX identifiers.</title>
<updated>2026-03-17T22:45:43Z</updated>
<author>
<name>Andre Noll</name>
<email>maan@tuebingen.mpg.de</email>
</author>
<published>2026-03-15T14:57:29Z</published>
<link rel='alternate' type='text/html' href='https://git.tue.mpg.de/cgit/paraslash/commit/?id=ea0cecf96e08c489fdcc94d046019f4ce46f58e2'/>
<id>urn:sha1:ea0cecf96e08c489fdcc94d046019f4ce46f58e2</id>
<content type='text'>
Generated with

	sed -i 's|Copyright.*Andre Noll.*|SPDX-License-Identifier: GPL-2.0 */|g' *.c *.h

followed by manually tweaking the result a bit. No license change intended.
</content>
</entry>
<entry>
<title>btr: Fix memory leak in btr_add_output_dont_free().</title>
<updated>2026-03-17T18:20:42Z</updated>
<author>
<name>Andre Noll</name>
<email>maan@tuebingen.mpg.de</email>
</author>
<published>2026-03-16T00:16:15Z</published>
<link rel='alternate' type='text/html' href='https://git.tue.mpg.de/cgit/paraslash/commit/?id=64971f3f7ab726ebcc23db22264b288f4210880d'/>
<id>urn:sha1:64971f3f7ab726ebcc23db22264b288f4210880d</id>
<content type='text'>
Quite a massive leak indeed, albeit only triggered by para_play:

	==25044== 423,420 bytes in 21,171 blocks are definitely lost in loss record 90 of 90
	==25044==    at 0x404ADDE: realloc (vg_replace_malloc.c:1804)
	==25044==    by 0x805AC34: arr_realloc (string.c:40)
	==25044==    by 0x805AC63: arr_alloc (string.c:61)
	==25044==    by 0x805AC7B: arr_zalloc (string.c:76)
	==25044==    by 0x805ACA2: zalloc (string.c:98)
	==25044==    by 0x8055445: new_btrb (buffer_tree.c:306)
	==25044==    by 0x8057070: btr_add_output_dont_free (buffer_tree.c:457)
	==25044==    by 0x805DC86: afh_recv_post_monitor (afh_recv.c:204)
	==25044==    by 0x805491C: call_post_monitor (sched.c:117)
	==25044==    by 0x805491C: sched_post_monitor (sched.c:143)
	==25044==    by 0x805491C: schedule (sched.c:183)
	==25044==    by 0x804F217: main (play.c:1228)

We leak one buffer reference (20 bytes on x86-32) per chunk when the buffer
can merged, which is true unless we reach the end of the buffer pool.
</content>
</entry>
<entry>
<title>Improve buffer tree documentation.</title>
<updated>2025-10-08T18:58:23Z</updated>
<author>
<name>Andre Noll</name>
<email>maan@tuebingen.mpg.de</email>
</author>
<published>2025-06-16T18:01:42Z</published>
<link rel='alternate' type='text/html' href='https://git.tue.mpg.de/cgit/paraslash/commit/?id=6d4f43fb93b41da6ae3e5590041e20d240a43c51'/>
<id>urn:sha1:6d4f43fb93b41da6ae3e5590041e20d240a43c51</id>
<content type='text'>
Minor improvements to the API description in buffer_tree.h, a lot of \a and
\p removal in buffer_tree.c, and the addition of some missing \ref statements.
</content>
</entry>
<entry>
<title>btr: Fix buffer tree merging.</title>
<updated>2025-07-13T14:38:46Z</updated>
<author>
<name>Andre Noll</name>
<email>maan@tuebingen.mpg.de</email>
</author>
<published>2025-07-08T20:28:24Z</published>
<link rel='alternate' type='text/html' href='https://git.tue.mpg.de/cgit/paraslash/commit/?id=dbac1c07dc31253ce2a9a2080e737de53138d9c5'/>
<id>urn:sha1:dbac1c07dc31253ce2a9a2080e737de53138d9c5</id>
<content type='text'>
The merge case of add_btrb_to_children() is rather broken. For one, if
the node has more than one child and we end up freeing the btr buffer in
the first iteration, we read stale contents when calling may_merge_btrb()
in the next iteration of the loop.

Secondly, not all callers of add_btrb_to_children() cope with btrb being
freed after merging occurred. In particular, the alsa writer triggers an
invalid read such as:

	at 0x804C7AC: btr_drop_buffer_reference (buffer_tree.c:351)
	by 0x804CD4A: btr_pushdown_br (buffer_tree.c:520)
	by 0x804CD4A: btr_pushdown (buffer_tree.c:539)
	by 0x804D948: check_wav_post_monitor (check_wav.c:194)
	by 0x804C31B: call_post_monitor (sched.c:118)
	by 0x804C31B: sched_post_monitor (sched.c:144)
	by 0x804C31B: schedule (sched.c:184)
	by 0x804A9CE: setup_and_schedule (write.c:97)
	by 0x804A9CE: main (write.c:149)

The problem is that btr_pushdown_br() calls add_btrb_to_children(), followed
by btr_drop_buffer_reference(). The first function frees br-&gt;btrb in the
may-merge case and the second function reads from this pointer.

This patch addresses both issues. It renames may_merge_btrb() to
try_merge_btrb(), checks more carefully if a merge is possible, and performs
the merge. This function needs to return whether the buffer was merged because
the callers have to clean up in different ways depending on whether or not
buffers were merged.

This retains the nice speedup of f64cbcc03484 at the cost of even more
complicated buffer tree code.

Reproducer (must run on a slow machine or under valgrind to trigger):

	para sender udp add 224.0.1.38:8000
	para_recv -r udp &gt; fec-encoded-data
	./para_filter -f fecdec -f mp3dec &lt; fec-encoded-data | ./para_write

Fixes: f64cbcc034844628b7e7817e27205cc6b48e9a18
</content>
</entry>
<entry>
<title>Remove -&gt;execute() of struct writer.</title>
<updated>2025-06-25T21:16:15Z</updated>
<author>
<name>Andre Noll</name>
<email>maan@tuebingen.mpg.de</email>
</author>
<published>2025-06-15T19:03:12Z</published>
<link rel='alternate' type='text/html' href='https://git.tue.mpg.de/cgit/paraslash/commit/?id=9c25613561f4feb488b1edd246026864039f2324'/>
<id>urn:sha1:9c25613561f4feb488b1edd246026864039f2324</id>
<content type='text'>
No writer implements this method.
</content>
</entry>
<entry>
<title>buffer_tree: Assert that we don't pass NULL to memcpy().</title>
<updated>2025-05-22T14:44:39Z</updated>
<author>
<name>Andre Noll</name>
<email>maan@tuebingen.mpg.de</email>
</author>
<published>2025-05-20T20:47:46Z</published>
<link rel='alternate' type='text/html' href='https://git.tue.mpg.de/cgit/paraslash/commit/?id=24c1b93962fc54d716d15ec914f6ca35b4b50b8b'/>
<id>urn:sha1:24c1b93962fc54d716d15ec914f6ca35b4b50b8b</id>
<content type='text'>
The buffer pointer cannot be NULL here because this only happens when the
buffer tree area is full, which is not the case thanks to the previous n &lt;=
btr_pool_unused(btrp) check.
</content>
</entry>
<entry>
<title>Include regex.h from para.h.</title>
<updated>2025-05-19T17:35:58Z</updated>
<author>
<name>Andre Noll</name>
<email>maan@tuebingen.mpg.de</email>
</author>
<published>2025-05-18T20:05:45Z</published>
<link rel='alternate' type='text/html' href='https://git.tue.mpg.de/cgit/paraslash/commit/?id=67388cd4fae0cfd1674aada937f4f4d2faeeee1f'/>
<id>urn:sha1:67388cd4fae0cfd1674aada937f4f4d2faeeee1f</id>
<content type='text'>
Every .c file includes it anyway.
</content>
</entry>
<entry>
<title>Constify buffer tree API.</title>
<updated>2024-05-08T17:45:52Z</updated>
<author>
<name>Andre Noll</name>
<email>maan@tuebingen.mpg.de</email>
</author>
<published>2023-01-02T13:43:42Z</published>
<link rel='alternate' type='text/html' href='https://git.tue.mpg.de/cgit/paraslash/commit/?id=4dfa81fee689335545bd16322cad6dbf84faa748'/>
<id>urn:sha1:4dfa81fee689335545bd16322cad6dbf84faa748</id>
<content type='text'>
A lot of functions of the buffer tree API don't modify the memory
referenced by the pointers passed. This patch marks these pointer
arguments as constant.
</content>
</entry>
<entry>
<title>btr: Merge buffers on insertion.</title>
<updated>2024-05-08T17:45:52Z</updated>
<author>
<name>Andre Noll</name>
<email>maan@tuebingen.mpg.de</email>
</author>
<published>2022-12-30T13:09:51Z</published>
<link rel='alternate' type='text/html' href='https://git.tue.mpg.de/cgit/paraslash/commit/?id=f64cbcc034844628b7e7817e27205cc6b48e9a18'/>
<id>urn:sha1:f64cbcc034844628b7e7817e27205cc6b48e9a18</id>
<content type='text'>
Currently add_btrb_to_children() simply adds the given buffer
reference to the input queue of all children of the given node even
if the newly added buffer reference points memory adjacent to the
previously added buffer.

Since several helpers iterate over all buffer references, performance
suffers, given enough buffer references. So merge buffers when
possible.

User time: 147s -&gt; 83s, speedup: 44%.
</content>
</entry>
</feed>
