changeset 984:3225a1ba050d

Fix a potential libconnwrap issue Based on a fix from the Debian centericq package, original patch by Julien Lemoine.
author Mikael Berthe <mikael@lilotux.net>
date Sat, 28 Oct 2006 17:38:53 +0200
parents e4f154f7c316
children b33ca4e1c37d
files mcabber/connwrap/connwrap.c
diffstat 1 files changed, 22 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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;
 }