Mir

Merge lp:~afrantzis/mir/fix-1353461-prompt-session-fd-leaks into lp:mir

Proposed by Alexandros Frantzis
Status: Merged
Approved by: Alexandros Frantzis
Approved revision: no longer in the source branch.
Merged at revision: 1843
Proposed branch: lp:~afrantzis/mir/fix-1353461-prompt-session-fd-leaks
Merge into: lp:mir
Diff against target: 73 lines (+12/-7)
2 files modified
src/server/frontend/session_mediator.cpp (+2/-0)
tests/acceptance-tests/test_prompt_session_client_api.cpp (+10/-7)
To merge this branch: bzr merge lp:~afrantzis/mir/fix-1353461-prompt-session-fd-leaks
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Daniel van Vugt Approve
Alan Griffiths Approve
Review via email: mp+230755@code.launchpad.net

Commit message

frontend,tests: Fix fd leaks in prompt session frontend code and tests

Description of the change

frontend,tests: Fix fd leaks in prompt session frontend code and tests

This MP fixes two leak sources: one in the tests (non-critical) and one in the prompt session frontend code, which is critical since it will eventually cause the server to run out of file descriptors.

To post a comment you must log in.
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

36 - static std::size_t const arbritary_fd_request_count = 3;

Personally, I'd leave this definition in the fixture (the test reader really shouldn't care what the number is - hence the "arbritary" name).

review: Approve
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

I prefer it as it is... with constants defined closer to where they're used. That's most helpful to the reader.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/server/frontend/session_mediator.cpp'
2--- src/server/frontend/session_mediator.cpp 2014-08-07 13:22:53 +0000
3+++ src/server/frontend/session_mediator.cpp 2014-08-14 08:24:45 +0000
4@@ -42,6 +42,7 @@
5 #include "mir/frontend/screencast.h"
6 #include "mir/frontend/prompt_session.h"
7 #include "mir/scene/prompt_session_creation_parameters.h"
8+#include "mir/fd.h"
9
10 #include "mir/geometry/rectangles.h"
11 #include "client_buffer_tracker.h"
12@@ -510,6 +511,7 @@
13 {
14 auto const fd = connection_context.fd_for_new_client(connect_handler);
15 response->add_fd(fd);
16+ resource_cache->save_fd(response, mir::Fd{fd});
17 }
18 }
19
20
21=== modified file 'tests/acceptance-tests/test_prompt_session_client_api.cpp'
22--- tests/acceptance-tests/test_prompt_session_client_api.cpp 2014-07-30 15:25:54 +0000
23+++ tests/acceptance-tests/test_prompt_session_client_api.cpp 2014-08-14 08:24:45 +0000
24@@ -23,6 +23,7 @@
25 #include "mir/scene/session.h"
26 #include "mir/frontend/session_credentials.h"
27 #include "mir/frontend/shell.h"
28+#include "mir/fd.h"
29
30 #include "mir_test_doubles/stub_session_authorizer.h"
31 #include "mir_test_framework/stubbed_server_configuration.h"
32@@ -194,10 +195,8 @@
33 MOCK_METHOD2(prompt_session_state_change,
34 void(MirPromptSession* prompt_provider, MirPromptSessionState state));
35
36- static std::size_t const arbritary_fd_request_count = 3;
37 std::mutex mutex;
38- std::size_t actual_fd_count = 0;
39- int actual_fds[arbritary_fd_request_count] = {};
40+ std::vector<mir::Fd> actual_fds;
41 std::condition_variable cv;
42 bool called_back = false;
43
44@@ -256,9 +255,11 @@
45 auto const self = static_cast<PromptSessionClientAPI*>(context);
46
47 std::unique_lock<decltype(self->mutex)> lock(self->mutex);
48- self->actual_fd_count = count;
49-
50- std::copy(fds, fds+count, self->actual_fds);
51+
52+ self->actual_fds.clear();
53+ for (size_t i = 0; i != count; ++i)
54+ self->actual_fds.push_back(mir::Fd{fds[i]});
55+
56 self->called_back = true;
57 self->cv.notify_one();
58 }
59@@ -330,11 +331,13 @@
60 MirPromptSession* prompt_session = mir_connection_create_prompt_session_sync(
61 connection, application_session_pid, null_state_change_callback, this);
62
63+ static std::size_t const arbritary_fd_request_count = 3;
64+
65 mir_prompt_session_new_fds_for_prompt_providers(
66 prompt_session, arbritary_fd_request_count, &client_fd_callback, this);
67
68 EXPECT_TRUE(wait_for_callback(std::chrono::milliseconds(500)));
69- EXPECT_THAT(actual_fd_count, Eq(arbritary_fd_request_count));
70+ EXPECT_THAT(actual_fds.size(), Eq(arbritary_fd_request_count));
71
72 mir_prompt_session_release_sync(prompt_session);
73 }

Subscribers

People subscribed via source and target branches