diff options
| author | Alexander Barton <alex@barton.de> | 2005-01-17 11:57:39 +0000 |
|---|---|---|
| committer | Alexander Barton <alex@barton.de> | 2005-01-17 11:57:39 +0000 |
| commit | 429b5f3ec9914a512708d1a718a9e40476a6c623 (patch) | |
| tree | 864f3494eb9ce97b6ed22959c4d38b1725f46fe7 /src | |
| parent | 81bacda627ee3f9e69212ddd8ab804e7d15f8c16 (diff) | |
| download | ngircd-429b5f3ec9914a512708d1a718a9e40476a6c623.tar.gz ngircd-429b5f3ec9914a512708d1a718a9e40476a6c623.zip | |
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>.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ngircd/conn.c | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/src/ngircd/conn.c b/src/ngircd/conn.c index f0bf5f08..aad61494 100644 --- a/src/ngircd/conn.c +++ b/src/ngircd/conn.c @@ -16,7 +16,7 @@ #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 <assert.h> @@ -1012,32 +1012,17 @@ New_Connection( INT Sock ) 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 ); if( ! ptr ) { - /* realloc() ist fehlgeschlagen. Nun malloc() probieren: */ - ptr = (POINTER *)malloc( sizeof( CONNECTION ) * new_size ); - if( ! ptr ) - { - /* 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 + Log( LOG_EMERG, "Can't allocate memory! [New_Connection]" ); + Simple_Message( new_sock, "ERROR: Internal error" ); + close( new_sock ); + return; } + #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 /* Adjust pointer to new block */ |