chiark / gitweb /
conf-parser: fix memory realloc error
authorYin Kangkai <kangkai.yin@intel.com>
Mon, 25 Nov 2013 15:14:46 +0000 (23:14 +0800)
committerLennart Poettering <lennart@poettering.net>
Mon, 25 Nov 2013 22:39:11 +0000 (23:39 +0100)
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.

src/shared/conf-parser.h

index 42602b3b085bae7c8b2a822409ef48a80e48bf5a..2d5aa31c3b244056e141f6c4aa72e624fbcafc14 100644 (file)
@@ -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;                                   \