fix invalid free in listing system players

fixes #176
This commit is contained in:
Tony Crisci
2020-05-15 13:13:19 -04:00
parent 92d54a5744
commit c41c479a4d
5 changed files with 39 additions and 5 deletions

View File

@@ -20,7 +20,11 @@ RUN pip3 install -r requirements.txt
ADD . /app ADD . /app
COPY data/test/dbus-system.conf /etc/dbus-1/system.d/test-dbus-system.conf
RUN meson --prefix=/usr build && \ RUN meson --prefix=/usr build && \
ninja -C build && ninja -C build install ninja -C build && ninja -C build install
RUN mkdir -p /run/dbus
ENV PYTHONASYNCIODEBUG=1 ENV PYTHONASYNCIODEBUG=1
CMD ["dbus-run-session", "python3", "-m", "pytest", "-svv"] ENV DBUS_SYSTEM_BUS_ADDRESS=unix:path=/var/run/dbus/system_bus_socket
CMD ["bash", "-c", "dbus-daemon --nopidfile --system && dbus-run-session python3 -m pytest -vv"]

View File

@@ -0,0 +1,14 @@
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<!-- This is only to be used in the test docker container -->
<policy user="root">
<allow own="*"/>
</policy>
<policy context="default">
<allow send_destination="*"/>
<allow receive_sender="*"/>
</policy>
</busconfig>

View File

@@ -1026,7 +1026,6 @@ GList *playerctl_list_players(GError **err) {
} }
GList *players = g_list_concat(session_players, system_players); GList *players = g_list_concat(session_players, system_players);
g_list_free(system_players);
return players; return players;
} }

View File

@@ -1,13 +1,18 @@
from dbus_next.service import ServiceInterface, dbus_property, method, signal, Variant from dbus_next.service import ServiceInterface, dbus_property, method, signal, Variant
from dbus_next import PropertyAccess, RequestNameReply from dbus_next import PropertyAccess, RequestNameReply, BusType
from dbus_next.aio import MessageBus from dbus_next.aio import MessageBus
import asyncio import asyncio
async def setup_mpris(*names, bus_address=None): async def setup_mpris(*names, bus_address=None, system=False):
async def setup(name): async def setup(name):
bus = await MessageBus(bus_address=bus_address).connect() if system:
bus_type = BusType.SYSTEM
else:
bus_type = BusType.SESSION
bus = await MessageBus(bus_type=bus_type,
bus_address=bus_address).connect()
player = MprisPlayer(bus) player = MprisPlayer(bus)
bus.export('/org/mpris/MediaPlayer2', player) bus.export('/org/mpris/MediaPlayer2', player)
bus.export('/org/mpris/MediaPlayer2', MprisRoot()) bus.export('/org/mpris/MediaPlayer2', MprisRoot())

View File

@@ -58,6 +58,18 @@ async def test_list_names(bus_address):
mpris.disconnect() mpris.disconnect()
@pytest.mark.asyncio
async def test_system_list_players(bus_address):
system_players = await setup_mpris('system', system=True)
session_players = await setup_mpris('session1', bus_address=bus_address)
playerctl = PlayerctlCli(bus_address, debug=False)
result = await playerctl.run('-l')
assert result.returncode == 0, result.stdout
assert result.stdout.split() == ['session1', 'system']
for mpris in system_players + session_players:
mpris.disconnect()
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_queries(bus_address): async def test_queries(bus_address):
[mpris] = await setup_mpris('queries', bus_address=bus_address) [mpris] = await setup_mpris('queries', bus_address=bus_address)