[Commit] librr/src rr.c,1.8,1.9 rr.h,1.13,1.14 rr_client.c,1.8,1.9
Carl Worth
commit at keithp.com
Thu Jun 26 21:07:28 PDT 2003
Committed by: cworth
Update of /local/src/CVS/librr/src
In directory home.keithp.com:/tmp/cvs-serv17788/src
Modified Files:
rr.c rr.h rr_client.c
Log Message:
Fix change of NOTFINISHED to NOTDONE.
Fix uninitialized fields in rr_client.
Free up unconsumed notices in queue during rr_client_fini.
Patched a few other memory leaks.
Index: rr.c
===================================================================
RCS file: /local/src/CVS/librr/src/rr.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- rr.c 25 Jun 2003 10:48:02 -0000 1.8
+++ rr.c 27 Jun 2003 03:07:25 -0000 1.9
@@ -54,6 +54,8 @@
return "out of memory";
case RR_STATUS_ROBOT_NOT_FOUND:
return "robot not found";
+ case RR_STATUS_TARGET_NOT_FOUND:
+ return "target not found";
case RR_STATUS_OCCUPIED:
return "space is already occupied";
case RR_STATUS_HISTORY_EMPTY:
@@ -96,8 +98,8 @@
return "not in game";
case RR_STATUS_NOT_PLAYING:
return "not playing";
- case RR_STATUS_NOT_FINISHED:
- return "game not finished";
+ case RR_STATUS_NOT_DONE:
+ return "game not done";
case RR_STATUS_NOT_BIDDING:
return "not bidding";
case RR_STATUS_NOT_LOWER:
@@ -112,9 +114,9 @@
return "too many moves";
case RR_STATUS_UNPARSED_ERROR:
return "unparsed error";
- default:
- return "unidentified error";
}
+
+ return "unidentified error";
}
static struct {
Index: rr.h
===================================================================
RCS file: /local/src/CVS/librr/src/rr.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- rr.h 26 Jun 2003 01:18:34 -0000 1.13
+++ rr.h 27 Jun 2003 03:07:25 -0000 1.14
@@ -58,7 +58,7 @@
RR_STATUS_NO_USER,
RR_STATUS_NOT_IN_GAME,
RR_STATUS_NOT_PLAYING,
- RR_STATUS_NOT_FINISHED,
+ RR_STATUS_NOT_DONE,
RR_STATUS_NOT_BIDDING,
RR_STATUS_NOT_LOWER,
RR_STATUS_NO_BID,
Index: rr_client.c
===================================================================
RCS file: /local/src/CVS/librr/src/rr_client.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- rr_client.c 26 Jun 2003 01:18:34 -0000 1.8
+++ rr_client.c 27 Jun 2003 03:07:25 -0000 1.9
@@ -122,6 +122,10 @@
{
rr_status_t status;
+ client->ptr = 0;
+ client->end = 0;
+ client->notice_queue = NULL;
+
status = _rr_client_connect (client, host, port);
if (status)
return status;
@@ -154,8 +158,15 @@
static rr_status_t
_rr_client_fini (rr_client_t *client)
{
+ rr_notice_t *notice;
+
_rr_client_disconnect (client);
+ while (rr_client_notice_pending (client)) {
+ rr_client_next_notice (client, ¬ice);
+ free (notice);
+ }
+
return RR_STATUS_SUCCESS;
}
@@ -376,12 +387,15 @@
_rr_strstrbuf_init (&strstrbuf);
while (1) {
+ char *s;
rr_strbuf_t strbuf;
_rr_strbuf_init (&strbuf);
status = _rr_client_read_word_strbuf (client,
&strbuf,
&delimiter);
- _rr_strstrbuf_append (&strstrbuf, _rr_strbuf_str (&strbuf));
+ s = _rr_strbuf_str (&strbuf);
+ _rr_strstrbuf_append (&strstrbuf, s);
+ free (s);
_rr_strbuf_fini (&strbuf);
if (status || delimiter == '\n')
break;
@@ -397,10 +411,9 @@
_rr_client_queue_notice (rr_client_t *client, char **arg)
{
rr_notice_elt_t *e = malloc (sizeof (rr_notice_elt_t)), **p;
- if (!e) {
- free (arg);
+ if (!e)
return RR_STATUS_NO_MEMORY;
- }
+
for (p = &client->notice_queue; *p; p = &(*p)->next);
e->notice = rr_notice_create (arg);
e->next = 0;
@@ -421,6 +434,7 @@
if (arg[0] && strcmp (arg[0], "NOTICE") == 0) {
_rr_strings_cdr (arg);
_rr_client_queue_notice (client, arg);
+ free (arg);
} else {
*response = arg;
return RR_STATUS_SUCCESS;
@@ -723,8 +737,8 @@
return RR_STATUS_NOT_IN_GAME;
else if (strcmp (error, "NOTPLAYING") == 0)
return RR_STATUS_NOT_PLAYING;
- else if (strcmp (error, "NOTFINISHED") == 0)
- return RR_STATUS_NOT_FINISHED;
+ else if (strcmp (error, "NOTDONE") == 0)
+ return RR_STATUS_NOT_DONE;
else if (strcmp (error, "NOTBIDDING") == 0)
return RR_STATUS_NOT_BIDDING;
else if (strcmp (error, "NOTLOWER") == 0)
@@ -744,25 +758,28 @@
static rr_status_t
_rr_client_recv (rr_client_t *client, const char *request, char ***argp)
{
+ rr_status_t status;
char **arg;
- rr_status_t status = _rr_client_reply (client, &arg);
+
+ status = _rr_client_reply (client, &arg);
+ if (status)
+ return status;
if (arg[0] && strncasecmp (arg[0], request, strlen (arg[0])) == 0) {
- status = RR_STATUS_SUCCESS;
_rr_strings_cdr (arg);
*argp = arg;
} else if (arg[0] && strcmp (arg[0], "ERROR") == 0) {
- status = _rr_client_error_to_status (arg[1]);
free (arg);
*argp = 0;
+ return _rr_client_error_to_status (arg[1]);
} else {
- status = RR_STATUS_PROTOCOL_ERROR;
- fprintf (stderr, "Unexpected response: %s\n",
- arg[0]);
+ fprintf (stderr, "Unexpected response: %s\n", arg[0]);
free (arg);
*argp = 0;
+ return RR_STATUS_PROTOCOL_ERROR;
}
- return status;
+
+ return RR_STATUS_SUCCESS;
}
int
More information about the Commit
mailing list