# HG changeset patch # User Mikael Berthe # Date 1162049933 -7200 # Node ID 3225a1ba050d812fdabf64caa1a72ca75c1bfbd5 # Parent e4f154f7c3162cc600bc4b50d90ce919bbef3b66 Fix a potential libconnwrap issue Based on a fix from the Debian centericq package, original patch by Julien Lemoine. diff -r e4f154f7c316 -r 3225a1ba050d mcabber/connwrap/connwrap.c --- a/mcabber/connwrap/connwrap.c Mon Oct 23 14:53:43 2006 +0200 +++ b/mcabber/connwrap/connwrap.c Sat Oct 28 17:38:53 2006 +0200 @@ -150,7 +150,11 @@ static sslsock *addsock(int fd) { sslsock *p; - socks = (sslsock *) realloc(socks, sizeof(sslsock)*++sockcount); + + if (socks) + socks = (sslsock *) realloc(socks, sizeof(sslsock)*++sockcount); + else + socks = (sslsock *) malloc(sizeof(sslsock)*++sockcount); p = &socks[sockcount-1]; @@ -168,21 +172,27 @@ sslsock *nsocks; nsockcount = 0; - nsocks = (sslsock *) malloc(sizeof(sslsock)*(sockcount-1)); + + if (sockcount > 1) { + nsocks = (sslsock *) malloc(sizeof(sslsock)*(sockcount-1)); - for(i = 0; i < sockcount; i++) { - if(socks[i].fd != fd) { - nsocks[nsockcount++] = socks[i]; - } else { - SSL_free(socks[i].ssl); + for(i = 0; i < sockcount; i++) { + if(socks[i].fd != fd) { + nsocks[nsockcount++] = socks[i]; + } else { + SSL_free(socks[i].ssl); + } } + + } else { + if (ctx) + SSL_CTX_free(ctx); + ctx = 0; + nsocks = 0; } - free(socks); - - SSL_CTX_free(ctx); - ctx = 0; - + if (socks) + free(socks); socks = nsocks; sockcount = nsockcount; }