Fix Bug: Memory leak

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
main
Jianhui Zhao 2017-11-12 17:20:13 +08:00
parent 84b4d2cdb5
commit 751e541776
1 changed files with 5 additions and 1 deletions

View File

@ -5,7 +5,11 @@
int uh_buf_init(struct uh_buf *buf, size_t initial_size) int uh_buf_init(struct uh_buf *buf, size_t initial_size)
{ {
buf->len = buf->size = 0; buf->len = buf->size = 0;
buf->base = NULL;
if (buf->base) {
free(buf->base);
buf->base = NULL;
}
if (initial_size > 0) { if (initial_size > 0) {
buf->base = malloc(initial_size); buf->base = malloc(initial_size);