Commit d8e6bbfa authored by Lev Walkin's avatar Lev Walkin

fix memory realloc

parent 52b88e1b
......@@ -279,10 +279,12 @@ static int _el_addbytes(const void *buffer, size_t size, void *el_buf_ptr) {
struct _el_buffer *el_buf = (struct _el_buffer *)el_buf_ptr;
if(el_buf->length + size > el_buf->allocated_size) {
size_t new_size;
size_t new_size = el_buf->allocated_size ? el_buf->allocated_size : 8;
void *p;
new_size = el_buf->allocated_size ? 2 * el_buf->allocated_size : 16;
do {
new_size <<= 2;
} while(el_buf->length + size > new_size);
p = REALLOC(el_buf->buf, new_size);
if(p) {
......
......@@ -80,21 +80,27 @@ typedef struct enc_dyn_arg {
} enc_dyn_arg;
static int
encode_dyn_cb(const void *buffer, size_t size, void *key) {
enc_dyn_arg *arg = key;
if(arg->length + size >= arg->allocated) {
void *p;
arg->allocated = arg->allocated ? (arg->allocated << 2) : size;
p = REALLOC(arg->buffer, arg->allocated);
if(!p) {
FREEMEM(arg->buffer);
memset(arg, 0, sizeof(*arg));
return -1;
}
arg->buffer = p;
}
memcpy(((char *)arg->buffer) + arg->length, buffer, size);
arg->length += size;
return 0;
enc_dyn_arg *arg = key;
if(arg->length + size >= arg->allocated) {
size_t new_size = arg->allocated ? arg->allocated : 8;
void *p;
do {
new_size <<= 2;
} while(arg->length + size >= new_size);
p = REALLOC(arg->buffer, new_size);
if(!p) {
FREEMEM(arg->buffer);
memset(arg, 0, sizeof(*arg));
return -1;
}
arg->buffer = p;
arg->allocated = new_size;
}
memcpy(((char *)arg->buffer) + arg->length, buffer, size);
arg->length += size;
return 0;
}
ssize_t
uper_encode_to_new_buffer(const asn_TYPE_descriptor_t *td,
......
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