aboutsummaryrefslogtreecommitdiffstats
path: root/scd/command.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2019-06-17 14:19:22 +0000
committerWerner Koch <[email protected]>2019-06-17 14:19:22 +0000
commitc594dcfc93486cd26e193aa5c82bb8a8f30ab57b (patch)
treedb49823e5231d3ea3210f3b7c9b042b892a54e1d /scd/command.c
parentscd: Slight change to app->fnc.do_with_keygrip. (diff)
downloadgnupg-c594dcfc93486cd26e193aa5c82bb8a8f30ab57b.tar.gz
gnupg-c594dcfc93486cd26e193aa5c82bb8a8f30ab57b.zip
scd: Add explict functions for 'app' reference counting.
* scd/app.c (app_ref): New. (app_unref): New. (release_application): Renamed to ... (app_unref_locked): this and remove arg locked_already. Change callers to use this or app_ref. * scd/command.c (open_card_with_request): (cmd_pksign, cmd_pkauth, cmd_pkdecrypt): Use app_ref and app_unref instead of accessing the counter directly. -- This is better in case we need to debug stuff. There is a real change however: We now lock and unlock the app before changing the reference count. The whole app locking business should be reviewed because we pass pointers along without immediately bumping the refcount. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'scd/command.c')
-rw-r--r--scd/command.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/scd/command.c b/scd/command.c
index 9173a6843..426615c8b 100644
--- a/scd/command.c
+++ b/scd/command.c
@@ -234,7 +234,7 @@ open_card_with_request (ctrl_t ctrl, const char *apptype, const char *serialno)
/* Re-scan USB devices. Release APP, before the scan. */
ctrl->app_ctx = NULL;
- release_application (app, 0);
+ app_unref (app);
if (serialno)
serialno_bin = hex_to_buffer (serialno, &serialno_bin_len);
@@ -804,14 +804,14 @@ cmd_pksign (assuan_context_t ctx, char *line)
if (app)
{
if (direct)
- app->ref_count++;
+ app_ref (app);
rc = app_sign (app, ctrl,
keyidstr, hash_algo,
pin_cb, ctx,
ctrl->in_data.value, ctrl->in_data.valuelen,
&outdata, &outdatalen);
if (direct)
- app->ref_count--;
+ app_unref (app);
}
else
rc = gpg_error (GPG_ERR_NO_SECKEY);
@@ -872,12 +872,12 @@ cmd_pkauth (assuan_context_t ctx, char *line)
if (app)
{
if (direct)
- app->ref_count++;
+ app_ref (app);
rc = app_auth (app, ctrl, keyidstr, pin_cb, ctx,
ctrl->in_data.value, ctrl->in_data.valuelen,
&outdata, &outdatalen);
if (direct)
- app->ref_count--;
+ app_unref (app);
}
else
rc = gpg_error (GPG_ERR_NO_SECKEY);
@@ -933,12 +933,12 @@ cmd_pkdecrypt (assuan_context_t ctx, char *line)
if (app)
{
if (direct)
- app->ref_count++;
+ app_ref (app);
rc = app_decipher (ctrl->app_ctx, ctrl, keyidstr, pin_cb, ctx,
ctrl->in_data.value, ctrl->in_data.valuelen,
&outdata, &outdatalen, &infoflags);
if (direct)
- app->ref_count--;
+ app_unref (app);
}
else
rc = gpg_error (GPG_ERR_NO_SECKEY);
@@ -1648,7 +1648,7 @@ cmd_restart (assuan_context_t ctx, char *line)
if (app)
{
ctrl->app_ctx = NULL;
- release_application (app, 0);
+ app_unref (app);
}
if (locked_session && ctrl->server_local == locked_session)
{
@@ -2169,7 +2169,8 @@ popup_prompt (void *opaque, int on)
}
-/* Helper to send the clients a status change notification. */
+/* Helper to send the clients a status change notification. Note that
+ * this fucntion assumes that APP is already locked. */
void
send_client_notifications (app_t app, int removal)
{
@@ -2199,7 +2200,7 @@ send_client_notifications (app_t app, int removal)
{
sl->ctrl_backlink->app_ctx = NULL;
sl->card_removed = 1;
- release_application (app, 1);
+ app_unref_locked (app);
}
if (!sl->event_signal || !sl->assuan_ctx)