Module unstable (memory problem-
Posted: Thu Jun 28, 2012 12:41 am
Hello friends!
I updated my version of Unreal to the last current stable.
Unfortunately I have a module it became incompatible.
And the second concern is that the memory is mismanaging also (I think).
What do the Ircd crash after some time (see rehash)
The author of this code is Debhian. I quote this because he does not quote in its code.
Does anyone could convert this module to the new version, and fix the problem of memory?
I have no knowledge of C, and, even less unrealircd.conf modules.
Thank you in advance because I really need this code and I'm in trouble!
THANK YOU!
I updated my version of Unreal to the last current stable.
Unfortunately I have a module it became incompatible.
And the second concern is that the memory is mismanaging also (I think).
What do the Ircd crash after some time (see rehash)
Code: Select all
#include "config.h"
#include "struct.h"
#include "common.h"
#include "sys.h"
#include "numeric.h"
#include "msg.h"
#include "proto.h"
#include "channel.h"
#include <time.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <io.h>
#endif
#include <fcntl.h>
#include "h.h"
#ifdef STRIPBADWORDS
#include "badwords.h"
#endif
#ifdef _WIN32
#include "version.h"
#endif
// Check if !LOL is here
int check_LOL(char *msg)
{
if(msg[0] == 33 && msg[1] == 108 && msg[2] == 111)
{
return 1;
}
else
{
return 0;
}
}
// Get rlz name in LOL
void LOL_getrlz(char *msg, char **retchar)
{
int i;
int etp=0;
int s=1;
char *rlz;
rlz=(char*)malloc(1*sizeof(char));
strcpy(rlz,"");
for(i=0;msg[i];i++)
{
if(msg[i]==32 && etp==1) { etp=2; }
if(etp==1) { s++; rlz=(char*)realloc(rlz,s*sizeof(char)); sprintf(rlz,"%s%c",rlz,msg[i]); }
if(msg[i]==32 && etp==0) { etp=1; }
}
*retchar=(char*)realloc(*retchar,sizeof(char)*(strlen(rlz)+1));
sprintf(*retchar,"%s",rlz);
}
// Mod HEADER
ModuleHeader MOD_HEADER(ANR_mod) =
{
"LOL_no_repeat",
"v1.0",
"No flood with !LOL",
"3.2-b8-1",
NULL
};
// Char Pile !
char **table;
// Char statut pile
int pile_num_s=0;
// Mod INFO
static ModuleInfo ANR_ModInfo;
// Hooking des CHANMSG
static Hook *CheckMsg;
// Fonction de hooking du CHANMSG
DLLFUNC char *LOL_checkmsg(aClient *, aClient *, aChannel *, char *, int);
// Mod init
DLLFUNC int MOD_INIT(ANR_mod)(ModuleInfo *modinfo)
{
int i;
bcopy(modinfo,&ANR_ModInfo,modinfo->size);
CheckMsg = HookAddPCharEx(ANR_ModInfo.handle, HOOKTYPE_CHANMSG, LOL_checkmsg);
/* Load char PILE 500K */
table=(char**)malloc(500*sizeof(*table));
for(i=0;i<500;i++)
{
table[i]=NULL;
table[i]=(char*)malloc(1024* sizeof((*table)[i]) );
}
return MOD_SUCCESS;
}
// Mod load
DLLFUNC int MOD_LOAD(m_dummy)(int module_load)
{
return MOD_SUCCESS;
}
// Mod unload
DLLFUNC int MOD_UNLOAD(m_dummy)(int module_unload)
{
int i;
/* Unload char pile 500K */
for(i=0;i<500;i++) { free(table[i]); }
HookDel(CheckMsg);
return MOD_SUCCESS;
}
DLLFUNC char *LOL_checkmsg(aClient *cptr, aClient *sptr, aChannel *chptr, char *text, int notice)
{
char *returnT;
char *rlzn;
char *rlzNchan;
int i;
if(check_LOL(text)==1)
{
rlzn=(char*)malloc(sizeof(char)*1);
LOL_getrlz(text,&rlzn);
rlzNchan=(char*)malloc((strlen(rlzn)+strlen(chptr->chname)+1)*sizeof(char));
sprintf(rlzNchan,"%s%s",rlzn,chptr->chname);
// Check if rlz isn't in 500K pile
for(i=0;i<500;i++) {
if(table[i]!=NULL) {
if(strcmp(rlzNchan,table[i])==0) {
sendto_one(sptr, ":%s 404 %s %s :The msg '%s' was already added with !LOL.",me.name, sptr->name,chptr->chname,rlzn);
return NULL;
}
}
}
// Sinon, on insère dans la pile 500K
if(pile_num_s > 500) { pile_num_s=0; }
table[pile_num_s]=(char*)malloc(sizeof((*table)[0])*(strlen(rlzNchan)+1));
sprintf(table[pile_num_s],"%s",rlzNchan);
pile_num_s++;
returnT=(char*)malloc((strlen(text)+1)*sizeof(char));
sprintf(returnT,"%s",text);
}
else
{
returnT=(char*)malloc((strlen(text)+1)*sizeof(char));
sprintf(returnT,"%s",text);
}
return returnT;
}
Does anyone could convert this module to the new version, and fix the problem of memory?
I have no knowledge of C, and, even less unrealircd.conf modules.
Thank you in advance because I really need this code and I'm in trouble!
THANK YOU!