# HG changeset patch # User Tero Marttila # Date 1240949438 -10800 # Node ID 4f8dc89d7cbbf31e407217ad52f3ae0742af69f3 # Parent d3e253d7281ae2defc506b77660c02909507bba4 fix line_proto bugs diff -r d3e253d7281a -r 4f8dc89d7cbb src/line_proto.c --- 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); diff -r d3e253d7281a -r 4f8dc89d7cbb src/line_proto.h --- 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);