[NeoStats-Devel] [Commits] r2748 - in trunk: . modules/quoteserv
[email protected] Fri, 19 Aug 2005 07:13:05 +1000
| Newsgroups | gmane.comp.neostats.devel |
|---|---|
| Message-ID | <[email protected]> |
Author: Mark
Date: Fri Aug 19 05:13:03 2005
New Revision: 2748
Modified:
trunk/ChangeLog
trunk/modules/quoteserv/main.c
Log:
quoteserv: fix win32 crash - strdup cannot be used in modules
Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog (original)
+++ trunk/ChangeLog Fri Aug 19 05:13:03 2005
@@ -4,6 +4,7 @@
Fish (F), Mark (M), DeadNotBuried (D)
===============================================================================
* NeoStats * Version 3.0.a3-dev
+ - QuoteServ: fix win32 crash - strdup cannot be used in modules. (M)
- Add strcasestr support function since not all systems support it. (M)
- New macros NS_CMD_END() and NS_SETTING_END() for terminating command and set
lists. (M)
Modified: trunk/modules/quoteserv/main.c
==============================================================================
--- trunk/modules/quoteserv/main.c (original)
+++ trunk/modules/quoteserv/main.c Fri Aug 19 05:13:03 2005
@@ -23,7 +23,6 @@
/* TODO:
* - Database sanity checking
- * - Free allocs made during database load
*/
#include "neostats.h"
@@ -142,19 +141,34 @@
return NS_SUCCESS;
while( os_fgets( buf, BUFSIZE*4, fp ) != NULL )
{
+ int len;
+
/* comment char */
if( buf[0] == '#' )
continue;
- /* TODO: memory leak if prefix/suffix used due to multiple strdup calls */
- ptr = strdup(buf);
- strip(ptr);
- dlog( DEBUG1, "read %s", ptr );
+ dlog( DEBUG1, "read %s", buf );
+ len = strlen( buf );
+ if( len == 0 )
+ continue;
+ ptr = ns_malloc( len );
if( ircstrncasecmp( buf, "PREFIX:", 7 ) == 0 )
- db->prefixstring = strdup(ptr + 7);
+ {
+ len -= 7;
+ strlcpy( ( ptr + 7 ), buf, len );
+ db->prefixstring = ptr;
+ }
else if( ircstrncasecmp( buf, "SUFFIX:", 7 ) == 0 )
- db->suffixstring = strdup(ptr + 7);
+ {
+ len -= 7;
+ strlcpy( ( ptr + 7 ), buf, len );
+ db->suffixstring = len;
+ }
else
+ {
+ strlcpy( ptr, buf, len );
AddStringToList( &db->stringlist, ptr, &db->stringcount );
+ }
+ strip(ptr);
}
os_fclose( fp );
return NS_SUCCESS;