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

This commit is contained in:
yoav@monfort.co.il 2016-02-07 20:24:28 +02:00
parent aa953b6ec3
commit fdbefc9d83

View File

@ -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) {
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->free = newlen;
buf->b = (unsigned char*)mp_realloc(buf->L, buf->b, buf->len + buf->free, newsize);
buf->free = newsize - buf->len;
}
memcpy(buf->b+buf->len,s,len);
buf->len += 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) {
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);
}