wm: glendy

Download patch

ref: d4470e0e463f45f155442ac599541184ae041c56
parent: 590d2b438b3ece75659ed51e4353e35519144cf5
author: mkf <mkf@cloud9p.org>
date: Thu Jun 6 08:33:12 EDT 2024

srv: dont't hard code values, free some values

--- a/srv.h
+++ b/srv.h
@@ -1,4 +1,5 @@
 #define playersock sockfd[turn % 2]
+#define INPUTSIZE 512
 
 extern int id;
 extern int sockfd[2];
--- a/srv5.c
+++ b/srv5.c
@@ -327,12 +327,12 @@
 	Game *g;
 	
 	/* sang bozorg */
-	s = emalloc(1024);
-	memset(s, 0, 1024);
+	s = (char*)emalloc(INPUTSIZE);
+	memset(s, 0, INPUTSIZE);
 	
 	g = (Game*)lookup(games, gid);
 	/* we could use local variables, but that not worth the trouble */
-	while((c = read(g->sockfd[player], s+n, 1) == 1) && n < 1024)
+	while((c = read(g->sockfd[player], s+n, 1) == 1) && n < INPUTSIZE)
 	{
 		/* silently drop CR from CRLF */
 		if(s[n] == '\r')
@@ -433,6 +433,7 @@
 		pthread_mutex_unlock(&game_lock);
 		free(s);
 	}
+	free(data);
 }
 static void
 play(Client *c1, Client *c2)
@@ -636,12 +637,12 @@
 	dprint("registerclient(%d)\n", fd);
 	
 	/* sang bozorg */
-	s = emalloc(1024);
-	memset(s, 0, 1024);
+	s = (char*)emalloc(INPUTSIZE);
+	memset(s, 0, INPUTSIZE);
 	
 
 	/* we could use local variables, but that not worth the trouble */
-	while((c = read(fd, s+n, 1) == 1) && n < 1024)
+	while((c = read(fd, s+n, 1) == 1) && n < INPUTSIZE)
 	{
 		/* silently drop CR from CRLF */
 		if(s[n] == '\r')