--- a/src/line_proto.c Tue Apr 28 23:10:30 2009 +0300
+++ b/src/line_proto.c Tue Apr 28 23:10:38 2009 +0300
@@ -102,16 +102,19 @@
{
struct line_proto *lp;
+ // alloc
+ if ((lp = calloc(1, sizeof(*lp))) == NULL)
+ return SET_ERROR(err, ERR_CALLOC);
+
// store
lp->transport = transport;
lp->buf_len = buf_size;
lp->callbacks = *callbacks;
lp->cb_arg = cb_arg;
- // allocate struct and buffers
+ // allocate buffers
if (
- (lp = calloc(1, sizeof(*lp))) == NULL
- || (lp->in_buf = malloc(buf_size)) == NULL
+ (lp->in_buf = malloc(buf_size)) == NULL
|| (lp->out_buf = malloc(buf_size)) == NULL
)
JUMP_SET_ERROR(err, ERR_CALLOC);
@@ -129,8 +132,7 @@
error:
// cleanup the lp
- if (lp)
- line_proto_destroy(lp);
+ line_proto_destroy(lp);
return ERROR_CODE(err);
}
@@ -281,6 +283,8 @@
int ret;
size_t ret_len;
+ assert(lp->out_offset);
+
// try and write the line
if ((ret = transport_write(lp->transport, lp->out_buf, lp->out_offset, &lp->err)) < 0)
return -ERROR_CODE(&lp->err);
--- a/src/line_proto.h Tue Apr 28 23:10:30 2009 +0300
+++ b/src/line_proto.h Tue Apr 28 23:10:38 2009 +0300
@@ -64,6 +64,8 @@
/**
* Flush out any buffered line fragment. Returns zero if the buffer was flushed empty, >0 if there's still fragments
* remaining, or -err on errors.
+ *
+ * It is a bug to call this if there is no data waiting to be sent.
*/
int line_proto_flush (struct line_proto *lp);