The first `malloc` of `rv` was checked for failure but the subsequent ones were
assumed to succeed.
#include <stdio.h>
#include <stdlib.h>
+#include <cgraph/likely.h>
#include <pathplan/vis.h>
typedef Ppoint_t ilcoord_t;
rv->N = n;
rv->Npoly = n_obs;
+ // bail out if any above allocations failed
+ if (UNLIKELY(rv->start == NULL || (n > 0 && (rv->P == NULL ||
+ rv->next == NULL ||
+ rv->prev == NULL)))) {
+ free(rv->prev);
+ free(rv->next);
+ free(rv->start);
+ free(rv->P);
+ free(rv);
+ return NULL;
+ }
+
/* build arrays */
i = 0;
for (poly_i = 0; poly_i < n_obs; poly_i++) {