gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-exchange] 03/04: -fix uninitialized variable and memory leak


From: gnunet
Subject: [taler-exchange] 03/04: -fix uninitialized variable and memory leak
Date: Tue, 02 May 2023 10:57:26 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository exchange.

commit 647ae694cc9f1aef44e792b96676b115231e8898
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon May 1 19:37:29 2023 +0200

    -fix uninitialized variable and memory leak
---
 src/kyclogic/plugin_kyclogic_oauth2.c | 120 ++++++++++++++++++----------------
 src/lib/exchange_api_wire.c           |   1 +
 src/testing/testing_api_cmd_oauth.c   |   1 +
 3 files changed, 67 insertions(+), 55 deletions(-)

diff --git a/src/kyclogic/plugin_kyclogic_oauth2.c 
b/src/kyclogic/plugin_kyclogic_oauth2.c
index 228525e2..c72b04b7 100644
--- a/src/kyclogic/plugin_kyclogic_oauth2.c
+++ b/src/kyclogic/plugin_kyclogic_oauth2.c
@@ -490,8 +490,6 @@ initiate_task (void *cls)
   struct PluginState *ps = pd->ps;
   char *hps;
   char *url;
-  char *redirect_uri;
-  char *redirect_uri_encoded;
   char legi_s[42];
 
   ih->task = NULL;
@@ -501,19 +499,27 @@ initiate_task (void *cls)
                    (unsigned long long) ih->legitimization_uuid);
   hps = GNUNET_STRINGS_data_to_string_alloc (&ih->h_payto,
                                              sizeof (ih->h_payto));
-  GNUNET_asprintf (&redirect_uri,
-                   "%skyc-proof/%s?state=%s",
-                   ps->exchange_base_url,
-                   pd->section,
-                   hps);
-  redirect_uri_encoded = TALER_urlencode (redirect_uri);
-  GNUNET_free (redirect_uri);
-  GNUNET_asprintf (&url,
-                   "%s?response_type=code&client_id=%s&redirect_uri=%s",
-                   pd->login_url,
-                   pd->client_id,
-                   redirect_uri_encoded);
-  GNUNET_free (redirect_uri_encoded);
+  {
+    char *redirect_uri_encoded;
+
+    {
+      char *redirect_uri;
+
+      GNUNET_asprintf (&redirect_uri,
+                       "%skyc-proof/%s?state=%s",
+                       ps->exchange_base_url,
+                       pd->section,
+                       hps);
+      redirect_uri_encoded = TALER_urlencode (redirect_uri);
+      GNUNET_free (redirect_uri);
+    }
+    GNUNET_asprintf (&url,
+                     "%s?response_type=code&client_id=%s&redirect_uri=%s",
+                     pd->login_url,
+                     pd->client_id,
+                     redirect_uri_encoded);
+    GNUNET_free (redirect_uri_encoded);
+  }
   /* FIXME-API: why do we *redirect* the client here,
      instead of making the HTTP request *ourselves*
      and forwarding the response? This prevents us
@@ -582,6 +588,37 @@ oauth2_initiate_cancel (struct 
TALER_KYCLOGIC_InitiateHandle *ih)
 }
 
 
+/**
+ * Cancel KYC proof.
+ *
+ * @param[in] ph handle of operation to cancel
+ */
+static void
+oauth2_proof_cancel (struct TALER_KYCLOGIC_ProofHandle *ph)
+{
+  if (NULL != ph->task)
+  {
+    GNUNET_SCHEDULER_cancel (ph->task);
+    ph->task = NULL;
+  }
+  if (NULL != ph->job)
+  {
+    GNUNET_CURL_job_cancel (ph->job);
+    ph->job = NULL;
+  }
+  if (NULL != ph->response)
+  {
+    MHD_destroy_response (ph->response);
+    ph->response = NULL;
+  }
+  GNUNET_free (ph->provider_user_id);
+  if (NULL != ph->attributes)
+    json_decref (ph->attributes);
+  GNUNET_free (ph->post_body);
+  GNUNET_free (ph);
+}
+
+
 /**
  * Function called to asynchronously return the final
  * result to the callback.
@@ -602,10 +639,8 @@ return_proof_response (void *cls)
           ph->attributes,
           ph->http_status,
           ph->response);
-  GNUNET_free (ph->provider_user_id);
-  if (NULL != ph->attributes)
-    json_decref (ph->attributes);
-  GNUNET_free (ph);
+  ph->response = NULL; /*Ownership passed to 'ph->cb'!*/
+  oauth2_proof_cancel (ph);
 }
 
 
@@ -1101,7 +1136,6 @@ oauth2_proof (void *cls,
                                    1));
   {
     char *client_id;
-    char *redirect_uri;
     char *client_secret;
     char *authorization_code;
     char *redirect_uri_encoded;
@@ -1109,13 +1143,17 @@ oauth2_proof (void *cls,
 
     hps = GNUNET_STRINGS_data_to_string_alloc (&ph->h_payto,
                                                sizeof (ph->h_payto));
-    GNUNET_asprintf (&redirect_uri,
-                     "%skyc-proof/%s?state=%s",
-                     ps->exchange_base_url,
-                     pd->section,
-                     hps);
-    redirect_uri_encoded = TALER_urlencode (redirect_uri);
-    GNUNET_free (redirect_uri);
+    {
+      char *redirect_uri;
+
+      GNUNET_asprintf (&redirect_uri,
+                       "%skyc-proof/%s?state=%s",
+                       ps->exchange_base_url,
+                       pd->section,
+                       hps);
+      redirect_uri_encoded = TALER_urlencode (redirect_uri);
+      GNUNET_free (redirect_uri);
+    }
     GNUNET_assert (NULL != redirect_uri_encoded);
     client_id = curl_easy_escape (ph->eh,
                                   pd->client_id,
@@ -1164,34 +1202,6 @@ oauth2_proof (void *cls,
 }
 
 
-/**
- * Cancel KYC proof.
- *
- * @param[in] ph handle of operation to cancel
- */
-static void
-oauth2_proof_cancel (struct TALER_KYCLOGIC_ProofHandle *ph)
-{
-  if (NULL != ph->task)
-  {
-    GNUNET_SCHEDULER_cancel (ph->task);
-    ph->task = NULL;
-  }
-  if (NULL != ph->job)
-  {
-    GNUNET_CURL_job_cancel (ph->job);
-    ph->job = NULL;
-  }
-  if (NULL != ph->response)
-  {
-    MHD_destroy_response (ph->response);
-    ph->response = NULL;
-  }
-  GNUNET_free (ph->post_body);
-  GNUNET_free (ph);
-}
-
-
 /**
  * Function to asynchronously return the 404 not found
  * page for the webhook.
diff --git a/src/lib/exchange_api_wire.c b/src/lib/exchange_api_wire.c
index f38ca86b..08498805 100644
--- a/src/lib/exchange_api_wire.c
+++ b/src/lib/exchange_api_wire.c
@@ -261,6 +261,7 @@ handle_wire_finished (void *cls,
       fbm = parse_fees (&master_pub,
                         fees,
                         &wr.details.ok.fees_len);
+      wr.details.ok.fees = fbm;
       if (NULL == fbm)
       {
         /* bogus reply */
diff --git a/src/testing/testing_api_cmd_oauth.c 
b/src/testing/testing_api_cmd_oauth.c
index 514b4ac8..0bcf2f68 100644
--- a/src/testing/testing_api_cmd_oauth.c
+++ b/src/testing/testing_api_cmd_oauth.c
@@ -310,6 +310,7 @@ cleanup (void *cls,
   (void) toe;
   if (NULL == rc)
     return;
+  MHD_destroy_post_processor (rc->pp);
   GNUNET_free (rc->code);
   GNUNET_free (rc->client_id);
   GNUNET_free (rc->redirect_uri);

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]