From: Yin Kangkai Date: Mon, 25 Nov 2013 15:14:46 +0000 (+0800) Subject: conf-parser: fix memory realloc error X-Git-Tag: v209~1296 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=4ae7885c2c4d89e1149c3fb186a4fe3b49787cc7 conf-parser: fix memory realloc error Otherwise there is some memory corruption and undefined behavior, e.g., in my case systemd-udev was always aborted at the _cleanup_freep_ around that code blocks. --- diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h index 42602b3b0..2d5aa31c3 100644 --- a/src/shared/conf-parser.h +++ b/src/shared/conf-parser.h @@ -202,7 +202,7 @@ int log_syntax_internal(const char *unit, int level, continue; \ \ *(xs + i) = x; \ - xs = realloc(xs, ++i + 1); \ + xs = realloc(xs, (++i + 1) * sizeof(type)); \ if (!xs) \ return -ENOMEM; \ *(xs + i) = invalid; \