Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kallsyms: use xmalloc() and xrealloc()

When malloc() or realloc() fails, there is not much userspace programs
can do. xmalloc() and xrealloc() are useful to bail out on a memory
allocation failure.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

+5 -18
+5 -18
scripts/kallsyms.c
··· 27 27 #include <ctype.h> 28 28 #include <limits.h> 29 29 30 + #include <xalloc.h> 31 + 30 32 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) 31 33 32 34 #define KSYM_NAME_LEN 512 ··· 170 168 * compressed together */ 171 169 len++; 172 170 173 - sym = malloc(sizeof(*sym) + len + 1); 174 - if (!sym) { 175 - fprintf(stderr, "kallsyms failure: " 176 - "unable to allocate required amount of memory\n"); 177 - exit(EXIT_FAILURE); 178 - } 171 + sym = xmalloc(sizeof(*sym) + len + 1); 179 172 sym->addr = addr; 180 173 sym->len = len; 181 174 sym->sym[0] = type; ··· 275 278 276 279 if (table_cnt >= table_size) { 277 280 table_size += 10000; 278 - table = realloc(table, sizeof(*table) * table_size); 279 - if (!table) { 280 - fprintf(stderr, "out of memory\n"); 281 - fclose(fp); 282 - exit (1); 283 - } 281 + table = xrealloc(table, sizeof(*table) * table_size); 284 282 } 285 283 286 284 table[table_cnt++] = sym; ··· 383 391 /* table of offset markers, that give the offset in the compressed stream 384 392 * every 256 symbols */ 385 393 markers_cnt = (table_cnt + 255) / 256; 386 - markers = malloc(sizeof(*markers) * markers_cnt); 387 - if (!markers) { 388 - fprintf(stderr, "kallsyms failure: " 389 - "unable to allocate required memory\n"); 390 - exit(EXIT_FAILURE); 391 - } 394 + markers = xmalloc(sizeof(*markers) * markers_cnt); 392 395 393 396 output_label("kallsyms_names"); 394 397 off = 0;