source: packages/net/quagga/patches/180-fix-lib-connect-memleak.patch @ 31190

Last change on this file since 31190 was 31190, checked in by florian, 5 years ago

[package] quagga: add upstream patches fixing memory leaks

Signed-off-by: Oliver Smith <olipro@…>

File size: 1.9 KB
  • lib/sockunion.c

    From b24b19f719fdd9c3d61a0c93552cd64d832d964c Mon Sep 17 00:00:00 2001
    From: Stephen Hemminger <shemminger@vyatta.com>
    Date: Tue, 6 Dec 2011 14:09:18 +0400
    Subject: [PATCH] lib: fix memory leak on connect() failure
    
    Change sockunion_log() to not use strdup(). This fixes a small memory
    leak that occurs on every failed connect(), and is simpler/cleaner.
    ---
     lib/sockunion.c |   23 +++++++++++------------
     1 files changed, 11 insertions(+), 12 deletions(-)
    
    a b sockunion_sizeof (union sockunion *su) 
    297297} 
    298298 
    299299/* return sockunion structure : this function should be revised. */ 
    300 static char * 
    301 sockunion_log (union sockunion *su) 
     300static const char * 
     301sockunion_log (union sockunion *su, char *buf, size_t len) 
    302302{ 
    303   static char buf[SU_ADDRSTRLEN]; 
    304  
    305303  switch (su->sa.sa_family)  
    306304    { 
    307305    case AF_INET: 
    308       snprintf (buf, SU_ADDRSTRLEN, "%s", inet_ntoa (su->sin.sin_addr)); 
    309       break; 
     306      return inet_ntop(AF_INET, &su->sin.sin_addr, buf, len); 
     307 
    310308#ifdef HAVE_IPV6 
    311309    case AF_INET6: 
    312       snprintf (buf, SU_ADDRSTRLEN, "%s", 
    313                 inet_ntop (AF_INET6, &(su->sin6.sin6_addr), buf, SU_ADDRSTRLEN)); 
     310      return inet_ntop(AF_INET6, &(su->sin6.sin6_addr), buf, len); 
    314311      break; 
    315312#endif /* HAVE_IPV6 */ 
     313 
    316314    default: 
    317       snprintf (buf, SU_ADDRSTRLEN, "af_unknown %d ", su->sa.sa_family); 
    318       break; 
     315      snprintf (buf, len, "af_unknown %d ", su->sa.sa_family); 
     316      return buf; 
    319317    } 
    320   return (XSTRDUP (MTYPE_TMP, buf)); 
    321318} 
    322319 
    323320/* sockunion_connect returns 
    sockunion_connect (int fd, union sockuni 
    379376    { 
    380377      if (errno != EINPROGRESS) 
    381378        { 
     379          char str[SU_ADDRSTRLEN]; 
    382380          zlog_info ("can't connect to %s fd %d : %s", 
    383                      sockunion_log (&su), fd, safe_strerror (errno)); 
     381                     sockunion_log (&su, str, sizeof str), 
     382                     fd, safe_strerror (errno)); 
    384383          return connect_error; 
    385384        } 
    386385    } 
Note: See TracBrowser for help on using the repository browser.