If realloc fails, do not override the still valid pointer with NULL.
Otherwise freeing the iterator won't free the previously allocated
buffer.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/82
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
offset += (off_t) partsz;
if (iter->bufsz < linesz + partsz) {
- iter->bufsz = linesz + partsz;
- iter->buf = realloc(iter->buf, iter->bufsz);
+ void *tmp;
+ size_t s;
- if (!iter->buf) {
+ s = linesz + partsz;
+ tmp = realloc(iter->buf, s);
+
+ if (!tmp) {
sv_errno = errno;
goto fail;
}
+ iter->bufsz = s;
+ iter->buf = tmp;
}
strncpy(iter->buf + linesz, buf, partsz);