buffer.c: fix dereference of invalid pointer.
using the pointer 'b->block' when it is possible that reallocation has moved the memory to another location. 'b->block' may therefore be an invalid pointer in some cases. use 'ret' intead.
This commit is contained in:
parent
ae91737fb1
commit
d18d581fd0
1 changed files with 1 additions and 1 deletions
2
buffer.c
2
buffer.c
|
|
@ -67,7 +67,7 @@ char* buffer_cstr_release(struct buffer *b) {
|
||||||
} else {
|
} else {
|
||||||
ret = (char *) b->block;
|
ret = (char *) b->block;
|
||||||
}
|
}
|
||||||
b->block[b->len + 1] = '\0';
|
ret[b->len + 1] = '\0';
|
||||||
} else {
|
} else {
|
||||||
ret = calloc(1, 1);
|
ret = calloc(1, 1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue