#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <fdt_region.h>
#include "fdt_host.h"
#include "libfdt_internal.h"
* we do another pass to actually record them.
*/
for (i = 0; i < 2; i++) {
- region = malloc(count * sizeof(struct fdt_region));
+ region = realloc(region, count * sizeof(struct fdt_region));
if (!region) {
fprintf(stderr, "Out of memory for %d regions\n",
count);
}
if (count <= max_regions)
break;
+ }
+ if (count > max_regions) {
free(region);
- fprintf(stderr, "Internal error with fdtgrep_find_region)(\n");
+ fprintf(stderr, "Internal error with fdtgrep_find_region()\n");
return -1;
}