Heartbeat context is not freed automatically by the library
[silc.git] / lib / silcutil / silcsockconn.c
index 942b30d8664e37ef46b36fd9762d39ccce7219da..25a56fe1aa658de5398f2502063c1da450cea65a 100644 (file)
@@ -23,7 +23,7 @@
 
 /* Heartbeat context */
 struct SilcSocketConnectionHBStruct {
-  uint32 heartbeat;
+  SilcUInt32 heartbeat;
   SilcSocketConnectionHBCb hb_callback;
   void *hb_context;
   SilcSchedule schedule;
@@ -73,10 +73,12 @@ void silc_socket_free(SilcSocketConnection sock)
     silc_buffer_free(sock->outbuf);
     if (sock->hb) {
       silc_schedule_task_del(sock->hb->schedule, sock->hb->hb_task);
-      silc_free(sock->hb->hb_context);
       silc_free(sock->hb);
     }
 
+    silc_free(sock->ip);
+    silc_free(sock->hostname);
+
     memset(sock, 'F', sizeof(*sock));
     silc_free(sock);
   }
@@ -120,14 +122,13 @@ SILC_TASK_CALLBACK(silc_socket_heartbeat)
    `schedule' is the application's scheduler. */
 
 void silc_socket_set_heartbeat(SilcSocketConnection sock, 
-                              uint32 heartbeat,
+                              SilcUInt32 heartbeat,
                               void *hb_context,
                               SilcSocketConnectionHBCb hb_callback,
                               SilcSchedule schedule)
 {
   if (sock->hb) {
     silc_schedule_task_del(schedule, sock->hb->hb_task);
-    silc_free(sock->hb->hb_context);
     silc_free(sock->hb);
   }
 
@@ -181,6 +182,7 @@ static void *silc_socket_host_lookup_start(void *context)
 {
   SilcSocketHostLookup lookup = (SilcSocketHostLookup)context;
   SilcSocketConnection sock = lookup->sock;
+  SilcSchedule schedule = lookup->schedule;
 
   if (lookup->port)
     sock->port = silc_net_get_remote_port(sock->sock);
@@ -189,10 +191,10 @@ static void *silc_socket_host_lookup_start(void *context)
   if (!sock->hostname && sock->ip)
     sock->hostname = strdup(sock->ip);
 
-  silc_schedule_task_add(lookup->schedule, sock->sock,
+  silc_schedule_task_add(schedule, sock->sock,
                         silc_socket_host_lookup_finish, lookup, 0, 1,
                         SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
-  silc_schedule_wakeup(lookup->schedule);
+  silc_schedule_wakeup(schedule);
 
   return NULL;
 }
@@ -224,10 +226,5 @@ void silc_socket_host_lookup(SilcSocketConnection sock,
   lookup->port = port_lookup;
 
   SILC_SET_HOST_LOOKUP(sock);
-
-#ifdef SILC_THREADS
   silc_thread_create(silc_socket_host_lookup_start, lookup, FALSE);
-#else
-  silc_socket_host_lookup_start((void *)lookup);
-#endif
 }