Fixed a memory leak when resizing the connection pool and realloc() failed.

Now we don't fall back to malloc(), which should be sane anyway.
Patch from Florian Westphal, <westphal@foo.fh-furtwangen.de>.
This commit is contained in:
Alexander Barton 2005-01-17 11:57:39 +00:00
parent 81bacda627
commit 429b5f3ec9
2 changed files with 11 additions and 23 deletions

View File

@ -12,6 +12,9 @@
ngIRCd CVSHEAD ngIRCd CVSHEAD
- Fixed a memory leak when resizing the connection pool and realloc()
failed. Now we don't fall back to malloc(), which should be sane anyway.
Patch from Florian Westphal, <westphal@foo.fh-furtwangen.de>.
- Added support for the Howl (http://www.porchdogsoft.com/products/howl/) - Added support for the Howl (http://www.porchdogsoft.com/products/howl/)
Rendezvous API, in addition to the API of Apple (Mac OS X). The available Rendezvous API, in addition to the API of Apple (Mac OS X). The available
APU will be autodetected when you call "./configure --with-rendezvous". APU will be autodetected when you call "./configure --with-rendezvous".
@ -553,4 +556,4 @@ ngIRCd 0.0.1, 31.12.2001
-- --
$Id: ChangeLog,v 1.248 2004/12/26 00:14:33 alex Exp $ $Id: ChangeLog,v 1.249 2005/01/17 11:57:39 alex Exp $

View File

@ -16,7 +16,7 @@
#include "portab.h" #include "portab.h"
static char UNUSED id[] = "$Id: conn.c,v 1.141 2004/12/22 17:37:41 alex Exp $"; static char UNUSED id[] = "$Id: conn.c,v 1.142 2005/01/17 11:57:39 alex Exp $";
#include "imp.h" #include "imp.h"
#include <assert.h> #include <assert.h>
@ -1012,32 +1012,17 @@ New_Connection( INT Sock )
return; return;
} }
/* zunaechst realloc() versuchen; wenn das scheitert, malloc() versuchen
* und Daten ggf. "haendisch" umkopieren. (Haesslich! Eine wirklich
* dynamische Verwaltung waere wohl _deutlich_ besser ...) */
ptr = (POINTER *)realloc( My_Connections, sizeof( CONNECTION ) * new_size ); ptr = (POINTER *)realloc( My_Connections, sizeof( CONNECTION ) * new_size );
if( ! ptr ) if( ! ptr )
{ {
/* realloc() ist fehlgeschlagen. Nun malloc() probieren: */ Log( LOG_EMERG, "Can't allocate memory! [New_Connection]" );
ptr = (POINTER *)malloc( sizeof( CONNECTION ) * new_size ); Simple_Message( new_sock, "ERROR: Internal error" );
if( ! ptr ) close( new_sock );
{ return;
/* Offenbar steht kein weiterer Sepeicher zur Verfuegung :-( */
Log( LOG_EMERG, "Can't allocate memory! [New_Connection]" );
Simple_Message( new_sock, "ERROR: Internal error" );
close( new_sock );
return;
}
/* Struktur umkopieren ... */
memcpy( ptr, My_Connections, sizeof( CONNECTION ) * Pool_Size );
#ifdef DEBUG
Log( LOG_DEBUG, "Allocated new connection pool for %ld items (%ld bytes). [malloc()/memcpy()]", new_size, sizeof( CONNECTION ) * new_size );
#endif
} }
#ifdef DEBUG #ifdef DEBUG
else Log( LOG_DEBUG, "Allocated new connection pool for %ld items (%ld bytes). [realloc()]", new_size, sizeof( CONNECTION ) * new_size ); Log( LOG_DEBUG, "Allocated new connection pool for %ld items (%ld bytes). [realloc()]", new_size, sizeof( CONNECTION ) * new_size );
#endif #endif
/* Adjust pointer to new block */ /* Adjust pointer to new block */