Commit 42cb422e authored by yoav@monfort.co.il's avatar yoav@monfort.co.il Committed by antirez
Browse files

cmsgpack: pass correct osize values to lua allocator, update correct buf free space in cmsgpack

parent 32535ff5
...@@ -119,10 +119,10 @@ mp_buf *mp_buf_new(lua_State *L) { ...@@ -119,10 +119,10 @@ mp_buf *mp_buf_new(lua_State *L) {
void mp_buf_append(mp_buf *buf, const unsigned char *s, size_t len) { void mp_buf_append(mp_buf *buf, const unsigned char *s, size_t len) {
if (buf->free < len) { if (buf->free < len) {
size_t newlen = buf->len+len; size_t newsize = (buf->len+len)*2;
buf->b = (unsigned char*)mp_realloc(buf->L, buf->b, buf->len, newlen*2); buf->b = (unsigned char*)mp_realloc(buf->L, buf->b, buf->len + buf->free, newsize);
buf->free = newlen; buf->free = newsize - buf->len;
} }
memcpy(buf->b+buf->len,s,len); memcpy(buf->b+buf->len,s,len);
buf->len += len; buf->len += len;
...@@ -130,7 +130,7 @@ void mp_buf_append(mp_buf *buf, const unsigned char *s, size_t len) { ...@@ -130,7 +130,7 @@ void mp_buf_append(mp_buf *buf, const unsigned char *s, size_t len) {
} }
void mp_buf_free(mp_buf *buf) { void mp_buf_free(mp_buf *buf) {
mp_realloc(buf->L, buf->b, buf->len, 0); /* realloc to 0 = free */ mp_realloc(buf->L, buf->b, buf->len + buf->free, 0); /* realloc to 0 = free */
mp_realloc(buf->L, buf, sizeof(*buf), 0); mp_realloc(buf->L, buf, sizeof(*buf), 0);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment