Compare commits

...

5 Commits

Author SHA1 Message Date
Pentium44 01d751aa42 Fixed missing free on malloc, no more crashing! 2021-08-15 03:12:56 -04:00
Pentium44 40f9056774 oops 2020-12-02 17:47:21 -08:00
Pentium44 939c2bd20a Cleanup 2020-12-02 17:46:45 -08:00
Pentium44 fcbe6f03db Fixed fat memory leak with malloc and free, going static 2020-12-02 17:41:34 -08:00
Pentium44 4298eecb68 Fixed fat memory leak with malloc and free, going static 2020-12-02 17:41:13 -08:00
3 changed files with 11 additions and 18 deletions

View File

@ -4,7 +4,6 @@
int irc_send(int socketfd, char *out) {
//printf(">> %s", out);
return send(socketfd, out, strlen(out), 0);
free(&socketfd);
}
int irc_connect(char *server, int port, int *socketfd) {

View File

@ -2,14 +2,14 @@
#include "irc.h"
#include "functions.h"
#include "dictionary.h"
#define BUF 36864
#define LINEBUF 4096
#define MAINBUFSIZ 36864
#define LINEBUFSIZ 4096
char *process_string(char *in, int n) {
int ii = -1, o, i, e;
char *nothing = "0";
char *buf = malloc(8128);
static char buf[MAINBUFSIZ];
for(i = 0; i < n; i++) {
ii++;
@ -35,11 +35,10 @@ char *process_string(char *in, int n) {
char *cmd;
char *chan;
char *e;
char *pass;
char *topic;
char *topicchan;
char *msg;
char *b = malloc(4096);
static char b[LINEBUFSIZ];
name = buf+1;
e = strchr(name,'!');
@ -99,13 +98,12 @@ char *process_string(char *in, int n) {
if(strncmp(msg, searchstr, strlen(searchstr))==0) {
sprintf(b,"PRIVMSG %s :%s, %s\r\n",chan,
name,dictionary[k].reply);
free(searchstr);
return b;
if(searchstr != NULL) free(searchstr);
return b;
}
free(searchstr);
if(searchstr != NULL) free(searchstr);
}
/*if(strncmp(msg, "@topic", 4)==0) {
if(strncmp(name, owner, strlen(owner))==0) {
(void)set_topic(e, topic, "./channels.log");
@ -329,13 +327,11 @@ char *process_string(char *in, int n) {
} // for loop
free(buf); // Free memory allocated with malloc
}
int main(int argc, char **argv) {
int socketfd, n;
char in[BUF+1], out[BUF+1], c[8128];
char in[MAINBUFSIZ+1], out[MAINBUFSIZ+1], c[LINEBUFSIZ];
char *pos, *action;
if(argc != 6) {
@ -388,12 +384,10 @@ int main(int argc, char **argv) {
char *str = process_string(in, n);
if(strncmp(str, "0", 1)!=0) {
irc_send(socketfd, str);
free(str);
fflush(stderr);
}
if(strncmp(str, "QUIT", 4)==0) {
fflush(stderr);
free(str);
break;
}
} // if(n > 0)

View File

@ -2,7 +2,7 @@
YOURUSER="Pentium44"
BOTNICK="MultiServ"
BOTPASS="changemeeeee"
BOTPASS="changeme"
ADDRESS="localhost"
PORT="1337"