Commit 477d6c76 authored by Jan Včelák's avatar Jan Včelák 🚀

fdset: fix incorrect size reallocation

parent 7c34a502
......@@ -24,16 +24,16 @@
/* Realloc memory or return error (part of fdset_resize). */
#define MEM_RESIZE(tmp, p, n) \
if ((tmp = realloc((p), (n))) == NULL) \
if ((tmp = realloc((p), (n) * sizeof(*p))) == NULL) \
return KNOT_ENOMEM; \
(p) = tmp;
static int fdset_resize(fdset_t *set, unsigned size)
{
void *tmp = NULL;
MEM_RESIZE(tmp, set->ctx, size * sizeof(void*));
MEM_RESIZE(tmp, set->pfd, size * sizeof(struct pollfd));
MEM_RESIZE(tmp, set->timeout, size * sizeof(timev_t));
MEM_RESIZE(tmp, set->ctx, size);
MEM_RESIZE(tmp, set->pfd, size);
MEM_RESIZE(tmp, set->timeout, size);
set->size = size;
return KNOT_EOK;
}
......
......@@ -39,7 +39,7 @@ typedef struct fdset {
unsigned size; /*!< Array size (allocated). */
void* *ctx; /*!< Context for each fd. */
struct pollfd *pfd; /*!< poll state for each fd */
time_t *timeout; /*!< Timeout for each fd (seconds precision). */
time_t *timeout; /*!< Timeout for each fd (seconds precision). */
} fdset_t;
/*! \brief Mark-and-sweep state. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment