#define MAX_DEPTH 32
static int name_depth = 0;
// static char name_list[MAX_DEPTH][PATH_MAX + 1];
-static char **name_list;
+static char **name_list = NULL;
static char *inode_buffer = NULL;
static void read_tables(void)
{
- inode_map = malloc(IMAPS * BLOCK_SIZE);
- if (!inode_map)
- die("Unable to allocate buffer for inode map");
- zone_map = malloc(ZMAPS * BLOCK_SIZE);
- if (!inode_map)
- die("Unable to allocate buffer for zone map");
+ inode_map = xmalloc(IMAPS * BLOCK_SIZE);
+ zone_map = xmalloc(ZMAPS * BLOCK_SIZE);
memset(inode_map, 0, sizeof(inode_map));
memset(zone_map, 0, sizeof(zone_map));
- inode_buffer = malloc(INODE_BUFFER_SIZE);
- if (!inode_buffer)
- die("Unable to allocate buffer for inodes");
- inode_count = malloc(INODES + 1);
- if (!inode_count)
- die("Unable to allocate buffer for inode count");
- zone_count = malloc(ZONES);
- if (!zone_count)
- die("Unable to allocate buffer for zone count");
+ inode_buffer = xmalloc(INODE_BUFFER_SIZE);
+ inode_count = xmalloc(INODES + 1);
+ zone_count = xmalloc(ZONES);
if (IMAPS * BLOCK_SIZE != read(IN, inode_map, IMAPS * BLOCK_SIZE))
die("Unable to read inode map");
if (ZMAPS * BLOCK_SIZE != read(IN, zone_map, ZMAPS * BLOCK_SIZE))
{
int i;
- name_list = malloc(sizeof(char *) * MAX_DEPTH);
- for (i = 0; i < MAX_DEPTH; i++) {
- name_list[i] = malloc(sizeof(char) * PATH_MAX + 1);
- }
+ name_list = xmalloc(sizeof(char *) * MAX_DEPTH);
+ for (i = 0; i < MAX_DEPTH; i++)
+ name_list[i] = xmalloc(sizeof(char) * PATH_MAX + 1);
}
+#if 0
+/* execute this atexit() to deallocate name_list[] */
+/* piptigger was here */
static void free_name_list(void)
{
- if (name_list) free(name_list);
+ int i;
+
+ if (name_list) {
+ for (i = 0; i < MAX_DEPTH; i++) {
+ if (name_list[i]) {
+ free(name_list[i]);
+ }
+ }
+ free(name_list);
+ }
}
+#endif
extern int fsck_minix_main(int argc, char **argv)
{
int retcode = 0;
alloc_name_list();
- atexit(free_name_list);
+ /* Don't bother to free memory. Exit does
+ * that automagically, so we can save a few bytes */
+ //atexit(free_name_list);
if (argc && *argv)
program_name = *argv;