Merge lp:~azzar1/unity/lockscreen-remove-leak-pam into lp:unity

Proposed by Andrea Azzarone
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 4270
Proposed branch: lp:~azzar1/unity/lockscreen-remove-leak-pam
Merge into: lp:unity
Diff against target: 64 lines (+25/-3)
1 file modified
lockscreen/UserAuthenticatorPam.cpp (+25/-3)
To merge this branch: bzr merge lp:~azzar1/unity/lockscreen-remove-leak-pam
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
Review via email: mp+341457@code.launchpad.net

Commit message

Fix memory leak in UserAuthenticatorPam::AuthenticateStart and add some debug messages.

To post a comment you must log in.
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lockscreen/UserAuthenticatorPam.cpp'
2--- lockscreen/UserAuthenticatorPam.cpp 2017-09-15 09:08:30 +0000
3+++ lockscreen/UserAuthenticatorPam.cpp 2018-03-15 12:54:29 +0000
4@@ -25,6 +25,8 @@
5 #include "unity-shared/UnitySettings.h"
6 #include "UnityCore/GLibWrapper.h"
7
8+#include <NuxCore/Logger.h>
9+
10 #include <cstring>
11 #include <security/pam_appl.h>
12 #include <vector>
13@@ -33,19 +35,31 @@
14 {
15 namespace lockscreen
16 {
17+namespace
18+{
19+DECLARE_LOGGER(logger, "unity.lockscreen");
20+}
21
22 bool UserAuthenticatorPam::AuthenticateStart(std::string const& username,
23 AuthenticateEndCallback const& authenticate_cb)
24 {
25 if (pam_handle_)
26+ {
27+ LOG_ERROR(logger) << "Unable to start authentication because another one has already been started";
28 return false;
29+ }
30
31 first_prompt_ = true;
32 username_ = username;
33 authenticate_cb_ = authenticate_cb;
34
35 glib::Error error;
36- g_thread_try_new(nullptr, AuthenticationThreadFunc, this, &error);
37+ g_autoptr(GThread) thread = g_thread_try_new(nullptr, AuthenticationThreadFunc, this, &error);
38+
39+ if (!thread || error)
40+ {
41+ LOG_ERROR(logger) << "Unable to create a new thread for PAM authentication: " << error.Message();
42+ }
43
44 return !error;
45 }
46@@ -88,8 +102,16 @@
47 conversation.conv = ConversationFunction;
48 conversation.appdata_ptr = static_cast<void*>(this);
49
50- return pam_start("unity", username_.c_str(),
51- &conversation, &pam_handle_) == PAM_SUCCESS;
52+ int ret = pam_start("unity", username_.c_str(),
53+ &conversation, &pam_handle_);
54+
55+ if (ret != PAM_SUCCESS)
56+ {
57+ LOG_ERROR(logger) << "Unable to start pam: " << pam_strerror(pam_handle_, ret);
58+ return false;
59+ }
60+
61+ return true;
62 }
63
64 int UserAuthenticatorPam::ConversationFunction(int num_msg,