From 4d79e3276b2ff67c729a4fd3ca611c69064b865d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 2 May 2019 11:52:54 +0200 Subject: [PATCH] auth-chain: embed copy of permission string in AuthCall Since the allocated AuthCall struct is small, we can just copy the permission string inside the struct. No need to strdup() the string separately. --- src/nm-auth-utils.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/nm-auth-utils.c b/src/nm-auth-utils.c index 49a931f153..808dfca23e 100644 --- a/src/nm-auth-utils.c +++ b/src/nm-auth-utils.c @@ -49,7 +49,7 @@ typedef struct { CList auth_call_lst; NMAuthChain *chain; NMAuthManagerCallId *call_id; - char *permission; + char permission[]; } AuthCall; /*****************************************************************************/ @@ -74,7 +74,6 @@ auth_call_free (AuthCall *call) if (call->call_id) nm_auth_manager_check_authorization_cancel (call->call_id); c_list_unlink_stale (&call->auth_call_lst); - g_free (call->permission); g_slice_free (AuthCall, call); } @@ -274,6 +273,7 @@ nm_auth_chain_add_call (NMAuthChain *self, { AuthCall *call; NMAuthManager *auth_manager = nm_auth_manager_get (); + gsize l_p_1; g_return_if_fail (self); g_return_if_fail (self->subject); @@ -283,11 +283,11 @@ nm_auth_chain_add_call (NMAuthChain *self, nm_assert ( nm_auth_subject_is_unix_process (self->subject) || nm_auth_subject_is_internal (self->subject)); - call = g_slice_new (AuthCall); - *call = (AuthCall) { - .chain = self, - .permission = g_strdup (permission), - }; + l_p_1 = strlen (permission) + 1; + call = g_malloc (sizeof (AuthCall) + l_p_1); + call->chain = self; + call->call_id = NULL; + memcpy (call->permission, permission, l_p_1); c_list_link_tail (&self->auth_call_lst_head, &call->auth_call_lst); call->call_id = nm_auth_manager_check_authorization (auth_manager, self->subject,