check
[oweals/gnunet.git] / src / core / core_api.c
index 3b5440135d41c9632927d7c916d30bde57fa4654..195e94e29d0dcf56a8cda2491dbb669b2c9ab4a0 100644 (file)
@@ -82,6 +82,11 @@ struct PeerRecord
    */
   void *pcic_cls;
 
+  /**
+   * Pointer to free when we call pcic.
+   */
+  void *pcic_ptr;
+
   /**
    * Request information ID for the given pcic (needed in case a
    * request is cancelled after being submitted to core and a new
@@ -419,6 +424,8 @@ disconnect_and_free_peer_entry (void *cls,
   if (NULL != (pcic = pr->pcic))
     {
       pr->pcic = NULL;
+      GNUNET_free_non_null (pr->pcic_ptr);
+      pr->pcic_ptr = NULL;
       pcic (pr->pcic_cls,
            &pr->peer,
            zero,
@@ -729,7 +736,8 @@ transmit_message (void *cls,
 #endif
          /* client decided to send nothing! */
          request_next_transmission (pr);
-         return 0;       
+         GNUNET_free (th);
+         return 0;       
        }
 #if DEBUG_CORE
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -741,7 +749,8 @@ transmit_message (void *cls,
        {
          GNUNET_break (0);
          request_next_transmission (pr);
-         return 0;
+         GNUNET_free (th);
+         return 0;
        }
       ret += sizeof (struct SendMessage);
       sm->header.size = htons (ret);
@@ -996,6 +1005,7 @@ main_notify_handler (void *cls,
       if (NULL == h->status_events)
         {
           GNUNET_break (0);
+         return;
         }
       if (msize < sizeof (struct PeerStatusNotifyMessage))
         {
@@ -1249,6 +1259,8 @@ main_notify_handler (void *cls,
        }
       pcic = pr->pcic;
       pr->pcic = NULL;
+      GNUNET_free_non_null (pr->pcic_ptr);
+      pr->pcic_ptr = NULL;
       if (pcic != NULL)
        pcic (pr->pcic_cls,
              &pr->peer,
@@ -1558,8 +1570,12 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
       if (minp == NULL) 
        {
          GNUNET_break (handle->queue_size != 0);
-         GNUNET_break (pr->queue_size == 0);
+         GNUNET_break (pr->queue_size == 1);
          GNUNET_free(th);
+#if DEBUG_CORE
+         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                     "Dropping transmission request: cannot drop queue head and limit is one\n");
+#endif
          return NULL;
        }
       if (priority <= minp->priority)
@@ -1568,6 +1584,7 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                      "Dropping transmission request: priority too low\n");
 #endif
+         GNUNET_free(th);
          return NULL; /* priority too low */
        }
       GNUNET_CONTAINER_DLL_remove (pr->pending_head,
@@ -1748,7 +1765,8 @@ GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h,
                                           &peer->hashPubKey))
     {
 #if DEBUG_CORE
-      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peers are already connected!\n");
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 
+                "Peers are already connected!\n");
 #endif
       return NULL;
     }
@@ -1918,6 +1936,7 @@ GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h,
                                    cm); 
   pr->pcic = info;
   pr->pcic_cls = info_cls;
+  pr->pcic_ptr = irc; /* for free'ing irc */
   if (h->control_pending_head == cm)
     trigger_next_request (h, GNUNET_NO);
   return irc;
@@ -1941,6 +1960,7 @@ GNUNET_CORE_peer_change_preference_cancel (struct GNUNET_CORE_InformationRequest
   struct GNUNET_CORE_Handle *h = irc->h;
   struct PeerRecord *pr = irc->pr;
 
+  GNUNET_assert (pr->pcic_ptr == irc);
   if (irc->cm != NULL)
     {
       GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
@@ -1950,6 +1970,7 @@ GNUNET_CORE_peer_change_preference_cancel (struct GNUNET_CORE_InformationRequest
     }
   pr->pcic = NULL;
   pr->pcic_cls = NULL;
+  pr->pcic_ptr = NULL;
   GNUNET_free (irc);
 }