Browse Source

m_fantasy: Apparently we can/should free newparv[] after do_cmd() na0 =]

Wazakindjes 3 years ago
parent
commit
b7af4bd410
1 changed files with 18 additions and 19 deletions
  1. 18 19
      u4/m_fantasy.c

+ 18 - 19
u4/m_fantasy.c

@@ -42,7 +42,7 @@ char svartypes[] = { '-', 'i', 'h', '*', 0 };
 // Dat dere module header
 ModuleHeader MOD_HEADER(m_fantasy) = {
 	"m_fantasy", // Module name
-	"$Id: v1.11 2018/07/22 Gottem$", // Version
+	"$Id: v1.12 2018/11/29 Gottem$", // Version
 	"Implements custom fantasy channel !cmds", // Description
 	"3.2-b8-1", // Modversion, not sure wat do
 	NULL
@@ -389,12 +389,12 @@ int fantasy_chanmsg(aClient *sptr, aChannel *chptr, char *text, int notice) {
 	fantasyCmd *fCmd = NULL; // iter8or lol
 	char *p, *p2, *p3; // For tokenising dat shit
 	char *ttemp; // Let's keep char *text intact yo
-	char *parv[MAXPARA]; // Muh array
+	char *parv[MAXPARA + 1]; // Muh array
 	int parc; // Arg counter
 	int i, j; // Quality iterators
 
 	char *cmdtemp; // Let's keep fCmd->cmdstr intact yo
-	char *cmdv[MAXPARA]; // Muh array
+	char *cmdv[MAXPARA + 1]; // Muh array
 	int cmdc; // Arg counter
 	char *multidelim; // In case of multiple nicks, wat delimiter to use
 	int gotmode; // Got MODE?
@@ -420,7 +420,7 @@ int fantasy_chanmsg(aClient *sptr, aChannel *chptr, char *text, int notice) {
 
 	// Double check imo tbh
 	if(!parv[0] || strlen(parv[0]) <= 1 || parv[0][0] != cmdChar) {
-		for(i = 0; i < parc; i++) // Need to free parv[] now lol
+		for(i = 0; parv[i]; i++) // Need to free parv[] now lol
 			FreeEm(parv[i]);
 		FreeEm(ttemp); // Also the token buffer thang
 		return HOOK_CONTINUE; // Just process the next hewk yo
@@ -478,6 +478,7 @@ int fantasy_chanmsg(aClient *sptr, aChannel *chptr, char *text, int notice) {
 				p2 = strtok(NULL, " \t"); // Get next t0ken
 			}
 			cmdv[cmdc] = NULL;
+			FreeEm(cmdtemp);
 
 			// Just a check lol, shouldn't happen cuz muh configtest() etc
 			if(!cmdv[0]) {
@@ -492,23 +493,27 @@ int fantasy_chanmsg(aClient *sptr, aChannel *chptr, char *text, int notice) {
 			// MODE is sorta special yo
 			if((gotmode = (!strcmp(cmdv[0], "MODE")))) {
 				// Check sanity of dem arguments yo
+				if(!cmdv[1] || !cmdv[2]) {
+					sendto_realops("[m_fantasy] The alias '%s' is configured incorrectly: missing arguments (channel and mode flag(s))", fCmd->alias);
+					// Gotta free em
+					for(i = 0; cmdv[i]; i++)
+						FreeEm(cmdv[i]);
+					continue;
+				}
+
 				if(cmdv[2][0] != '+' && cmdv[2][0] != '-') {
 					sendto_realops("[m_fantasy] The alias '%s' is configured incorrectly: invalid mode direction, must be either + or -", fCmd->alias);
 					// Gotta free em
 					for(i = 0; cmdv[i]; i++)
 						FreeEm(cmdv[i]);
-
-					FreeEm(cmdtemp);
 					continue;
 				}
 
 				if(!isalpha(cmdv[2][1])) {
-					sendto_realops("[m_fantasy] The alias '%s' is configured incorrectly: invalid mode flag, must be an alpbabetic character", fCmd->alias);
+					sendto_realops("[m_fantasy] The alias '%s' is configured incorrectly: invalid mode flag, must be an alphabetic character", fCmd->alias);
 					// Gotta free em
 					for(i = 0; cmdv[i]; i++)
 						FreeEm(cmdv[i]);
-
-					FreeEm(cmdtemp);
 					continue;
 				}
 			}
@@ -534,7 +539,6 @@ int fantasy_chanmsg(aClient *sptr, aChannel *chptr, char *text, int notice) {
 					cmdv[i] = strdup(multitmp); // Dup it agen
 					FreeEm(multitmp);
 				}
-
 				stoppem = fixSpecialVars(cmdv, i, sptr, chptr, parc, parv, multidelim); // Numeric variables, $1 through $9 with possible suffixes =]
 			}
 
@@ -560,23 +564,18 @@ int fantasy_chanmsg(aClient *sptr, aChannel *chptr, char *text, int notice) {
 			}
 
 			// Free our shit lol
-			// Apparently do_cmd() may rip the cmdv[] array =]
-			if(!passem && !flushem) {
-				for(i = 0; i < cmdc; i++)
-					FreeEm(cmdv[i]);
-			}
-
-			FreeEm(cmdtemp);
+			for(i = 0; cmdv[i]; i++)
+				FreeEm(cmdv[i]);
 
 			// Since FLUSH_BUFFER frees the sptr, let's break out ;]
-			if(!sptr || flushem)
+			if(flushem || !sptr)
 				break;
 		}
 	}
 
 	// Free the remaining stuff
 	FreeEm(cmd);
-	for(i = 0; i < parc; i++)
+	for(i = 0; parv[i]; i++)
 		FreeEm(parv[i]);
 	FreeEm(ttemp);
 	return HOOK_CONTINUE; // Just process the next hewk lol