lwip-devel
[Top][All Lists]
Advanced

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

[lwip-devel] Netconn_new_with_proto__and_callback problem


From: Frédéric BERNON
Subject: [lwip-devel] Netconn_new_with_proto__and_callback problem
Date: Wed, 21 Mar 2007 18:27:40 +0100

If there is a error during this function, some resources could be consume but 
not freed.
Can you check there is no "external" processing, and I can commit that?

struct
netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u16_t proto,
                                   void (*callback)(struct netconn *, enum 
netconn_evt, u16_t len))
{
  struct netconn *conn;
  struct api_msg msg;

  conn = memp_malloc(MEMP_NETCONN);
  if (conn == NULL) {
    return NULL;
  }
  
  conn->err = ERR_OK;
  conn->type = t;
  conn->pcb.tcp = NULL;

  if ((conn->mbox = sys_mbox_new()) == SYS_MBOX_NULL) {
    memp_free(MEMP_NETCONN, conn);
    return NULL;
  }
  conn->recvmbox = SYS_MBOX_NULL;
  conn->acceptmbox = SYS_MBOX_NULL;
  conn->sem = sys_sem_new(0);
  if (conn->sem == SYS_SEM_NULL) {
    sys_mbox_free(conn->mbox); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<    
    memp_free(MEMP_NETCONN, conn);
    return NULL;
  }
  conn->state        = NETCONN_NONE;
  conn->socket       = 0;
  conn->callback     = callback;
  conn->recv_avail   = 0;
#if LWIP_SO_RCVTIMEO
  conn->recv_timeout = 0;
#endif /* LWIP_SO_RCVTIMEO */

  msg.type = API_MSG_NEWCONN;
  msg.msg.msg.bc.port = proto; /* misusing the port field */
  msg.msg.conn = conn;
  api_msg_post(&msg);  

  if ( conn->err != ERR_OK ) {
    sys_sem_free(conn->sem);   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<    
 
    sys_mbox_free(conn->mbox); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<    
    memp_free(MEMP_NETCONN, conn);
    return NULL;
  }

  return conn;
}       

 
  
====================================
Frédéric BERNON 
HYMATOM SA 
Chef de projet informatique 
Microsoft Certified Professional 
Tél. : +33 (0)4-67-87-61-10 
Fax. : +33 (0)4-67-70-85-44 
Email : address@hidden 
Web Site : http://www.hymatom.fr 
====================================
P Avant d'imprimer, penser à l'environnement

Attachment: Frédéric BERNON.vcf
Description: Frédéric BERNON.vcf


reply via email to

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