From 15b93b378020b59031b991abe31b130ca105be03 Mon Sep 17 00:00:00 2001 From: Ethan Benson Date: Fri, 29 Jul 2005 04:29:18 +0000 Subject: [PATCH] Pretend to allocate/deallocate memory correctly * Pretend like we actually manage memory properly by calling free() on things which were malloc()'ed or strdup()'ed. (Patch from Dustin Kirkland). git-archimport-id: erbenson@alaska.net--public/yaboot--devel--1.3--patch-84 --- 0arch-timestamps0 | 56 +++++++++++++++++++++++----------------------- ChangeLog | 16 +++++++++++++ second/file.c | 9 +++++--- second/partition.c | 6 +++++ second/yaboot.c | 52 +++++++++++++++++++++++++----------------- 5 files changed, 88 insertions(+), 51 deletions(-) diff --git a/0arch-timestamps0 b/0arch-timestamps0 index 0a2f69e..84bd38c 100644 --- a/0arch-timestamps0 +++ b/0arch-timestamps0 @@ -1,7 +1,7 @@ -./0arch-timestamps0 1120448537 1120953071 +./0arch-timestamps0 1120953079 1122611350 ./BUGS 1109049412 1000991730 ./COPYING 1109049412 1000991730 -./ChangeLog 1120952850 1120953067 +./ChangeLog 1122611216 1122611345 ./Config 1109049412 1002101497 ./INSTALL 1109049412 1000991730 ./Makefile 1109049412 1089576723 @@ -22,18 +22,18 @@ ./doc/examples/simpleboot.chrp 1109049412 1068017750 ./doc/examples/yaboot.conf.multi-boot 1109049412 1006348765 ./doc/examples/yaboot.conf.rs6000 1109049412 1006348765 -./doc/examples 1120953070 1068017750 +./doc/examples 1122611349 1068017750 ./doc/yaboot-howto.de.sgml 1109049413 1096186109 ./doc/yaboot-howto.sgml 1109049413 1096186082 -./doc 1120953070 1096186109 +./doc 1122611349 1096186109 ./etc/yaboot.conf 1109049413 1006348765 -./etc 1120953070 1007269243 +./etc 1122611349 1007269243 ./first/ofboot 1118285749 1065311880 -./first 1120953070 1071492158 +./first 1122611349 1071492158 ./include/asm/elf.h 1109049413 1000991730 ./include/asm/ppc_asm.tmpl 1109049413 1000991730 ./include/asm/processor.h 1109049413 1000991730 -./include/asm 1120953071 1007269243 +./include/asm 1122611349 1007269243 ./include/bootinfo.h 1109049413 1007200690 ./include/byteorder.h 1109049413 1000991730 ./include/cfg.h 1109049413 1007200690 @@ -42,12 +42,12 @@ ./include/debug.h 1109049413 1007200690 ./include/errors.h 1109049413 1007200690 ./include/et/com_err.h 1109049413 1000991731 -./include/et 1120953071 1007269243 +./include/et 1122611349 1007269243 ./include/ext2fs/bitops.h 1109049413 1003927524 ./include/ext2fs/ext2_err.h 1109049413 1003927524 ./include/ext2fs/ext2_io.h 1109049413 1003927524 ./include/ext2fs/ext2fs.h 1109049413 1003927524 -./include/ext2fs 1120953071 1007269243 +./include/ext2fs 1122611350 1007269243 ./include/file.h 1109049413 1007200690 ./include/fs.h 1109049413 1007200690 ./include/linux/elf.h 1109049413 1000991731 @@ -55,12 +55,12 @@ ./include/linux/iso_fs.h 1109049413 1000991731 ./include/linux/stat.h 1109049413 1000991731 ./include/linux/types.h 1109049413 1000991731 -./include/linux 1120953071 1007269243 +./include/linux 1122611350 1007269243 ./include/mac-part.h 1109049413 1007200690 ./include/md5.h 1109049413 1000991730 ./include/prom.h 1109049413 1007200690 ./include/reiserfs/reiserfs.h 1109049413 1025684115 -./include/reiserfs 1120953071 1025684115 +./include/reiserfs 1122611350 1025684115 ./include/setjm2.h 1109049413 1000991730 ./include/setjmp.h 1109049413 1000991730 ./include/stdlib.h 1109049413 1000991730 @@ -68,35 +68,34 @@ ./include/swab.h 1109049413 1000991730 ./include/types.h 1109049413 1000991730 ./include/xfs/xfs.h 1109049413 1002101334 -./include/xfs 1120953071 1007269244 +./include/xfs 1122611350 1007269244 ./include/yaboot.h 1109049413 1007200690 ./include/amiga-part.h 1116558586 1116558522 -./include/fdisk-part.h 1120952841 1120952841 -./include/partition.h 1120952841 1120952841 -./include 1120953071 1120952841 +./include/fdisk-part.h 1120953080 1120952841 +./include/partition.h 1120953080 1120952841 +./include 1122611349 1120952841 ./lib/ctype.c 1109049413 1000991731 ./lib/libext2fs.a 1109049413 1003927524 -./lib/malloc.c 1109049413 1007200690 +./lib/malloc.c 1122610545 1007200690 ./lib/nosys.c 1109049413 1000991731 ./lib/string.S 1109049413 1007200690 ./lib/strtol.c 1109049413 1000991731 ./lib/vsprintf.c 1109049413 1000991731 ./lib/strstr.c 1119929028 1116476589 -./lib 1120953071 1116476589 +./lib 1122610543 1116476589 ./man/bootstrap.8 1116558691 1000991731 ./man/mkofboot.8 1116558691 1006348765 ./man/ofpath.8 1116558691 1000991731 ./man/yaboot.conf.5 1116558691 1004256691 ./man/yabootconfig.8 1116558691 1027929577 ./man/ybin.8 1116558691 1006348765 -./man/yaboot.8 1116558691 1090699543 -./man 1120953071 1116476667 +./man/yaboot.8 1121662318 1090699543 +./man 1122611350 1116476667 ./man.patch 1116558699 1006348761 ./second/cache.S 1120952570 1007200690 ./second/cfg.c 1120952570 1007200690 ./second/cmdline.c 1120952570 1032059589 ./second/crt0.S 1120952570 1000991731 -./second/file.c 1120952570 1044868693 ./second/fs.c 1120952570 1032059574 ./second/fs_ext2.c 1120952570 1032059564 ./second/fs_iso.c 1120952570 1007200690 @@ -106,16 +105,17 @@ ./second/md5.c 1120952570 1032059532 ./second/prom.c 1120952570 1067937197 ./second/setjmp.S 1120952570 1000991732 -./second/yaboot.c 1120952570 1032059504 -./second/fs_of.c 1120952841 1120952841 -./second/partition.c 1120952841 1120952841 -./second 1120953071 1120952841 +./second/fs_of.c 1120953080 1120952841 +./second/file.c 1122611207 1122611207 +./second/partition.c 1122611207 1122611207 +./second/yaboot.c 1122611207 1122611207 +./second 1122611350 1122611207 ./util/elfextract.c 1109049413 1007303237 ./util/addnote.c 1109049413 1107321884 -./util 1120953071 1107321884 -./ybin/mkofboot 1120953071 1073219938 +./util 1122611350 1107321884 +./ybin/mkofboot 1122611350 1073219938 ./ybin/ofpath 1120448537 1120448442 ./ybin/yabootconfig 1117166139 1089576743 ./ybin/ybin 1120448039 1120447943 -./ybin 1120953071 1120448442 -. 1120953070 1120953067 +./ybin 1122611350 1120448442 +. 1122611349 1122611345 diff --git a/ChangeLog b/ChangeLog index 592cbbc..7002c5d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,22 @@ # arch-tag: automatic-ChangeLog--erbenson@alaska.net--public/yaboot--devel--1.3 # +2005-07-29 04:29:18 GMT Ethan Benson patch-84 + + Summary: + Pretend to allocate/deallocate memory correctly + Revision: + yaboot--devel--1.3--patch-84 + + * Pretend like we actually manage memory properly by calling free() on + things which were malloc()'ed or strdup()'ed. + (Patch from Dustin Kirkland). + + modified files: + 0arch-timestamps0 ChangeLog second/file.c second/partition.c + second/yaboot.c + + 2005-07-09 23:51:20 GMT Ethan Benson patch-83 Summary: diff --git a/second/file.c b/second/file.c index b5763a2..ed70376 100644 --- a/second/file.c +++ b/second/file.c @@ -78,8 +78,8 @@ parse_device_path(char *imagepath, char *defdevice, int defpart, if (!imagepath) return 0; - else - ipath = strdup(imagepath); + else if (!(ipath = strdup(imagepath))) + return 0; if (defdevice) defdev = strdup(defdevice); @@ -89,6 +89,8 @@ parse_device_path(char *imagepath, char *defdevice, int defpart, if ((ptr = strrchr(defdev, ':')) != NULL) *ptr = 0; /* remove trailing : from defdevice if necessary */ } + } else { + return 0; } /* if there is no : then there is no filename or partition. must @@ -123,6 +125,7 @@ parse_device_path(char *imagepath, char *defdevice, int defpart, } else if (strlen(ipath)) { result->file = strdup(ipath); } else { + free(defdev); return 0; } @@ -137,7 +140,7 @@ parse_device_path(char *imagepath, char *defdevice, int defpart, free(ipath); if (defdev) - free(defdev); + free(defdev); return 1; } diff --git a/second/partition.c b/second/partition.c index a95a1b2..0582309 100644 --- a/second/partition.c +++ b/second/partition.c @@ -280,6 +280,10 @@ partition_amiga_lookup( const char *dev_name, prom_handle disk, possible = amiga_block[AMIGA_RDBLIMIT]/32 +1; used = (unsigned int *) malloc (sizeof (unsigned int) * (possible + 1)); + if (!used) { + prom_printf("Can't allocate memory\n"); + return; + } for (i=0; i < possible; i++) used[i] = 0; @@ -322,6 +326,8 @@ partition_amiga_lookup( const char *dev_name, prom_handle disk, prom_blksize, 0 ); } + if (used) + free(used); } struct partition_t* diff --git a/second/yaboot.c b/second/yaboot.c index c315787..cf920a1 100644 --- a/second/yaboot.c +++ b/second/yaboot.c @@ -435,7 +435,7 @@ bail: if (opened) file.fs->close(&file); - if (result != 1 && conf_file) + if (conf_file) free(conf_file); return result; @@ -1081,7 +1081,7 @@ load_elf32(struct boot_file_t *file, loadinfo_t *loadinfo) /* Read the rest of the Elf header... */ if ((*(file->fs->read))(file, size, &e->e_version) < size) { prom_printf("\nCan't read Elf32 image header\n"); - return 0; + goto bail; } DEBUG_F("Elf32 header:\n"); @@ -1100,24 +1100,24 @@ load_elf32(struct boot_file_t *file, loadinfo_t *loadinfo) if (e->e_phnum > MAX_HEADERS) { prom_printf ("Can only load kernels with one program header\n"); - return 0; + goto bail; } ph = (Elf32_Phdr *)malloc(sizeof(Elf32_Phdr) * e->e_phnum); if (!ph) { prom_printf ("Malloc error\n"); - return 0; + goto bail; } /* Now, we read the section header */ if ((*(file->fs->seek))(file, e->e_phoff) != FILE_ERR_OK) { prom_printf ("seek error\n"); - return 0; + goto bail; } if ((*(file->fs->read))(file, sizeof(Elf32_Phdr) * e->e_phnum, ph) != sizeof(Elf32_Phdr) * e->e_phnum) { prom_printf ("read error\n"); - return 0; + goto bail; } /* Scan through the program header @@ -1144,7 +1144,7 @@ load_elf32(struct boot_file_t *file, loadinfo_t *loadinfo) if (loadinfo->memsize == 0) { prom_printf("Can't find a loadable segment !\n"); - return 0; + goto bail; } /* leave some room (1Mb) for boot infos */ @@ -1173,7 +1173,7 @@ load_elf32(struct boot_file_t *file, loadinfo_t *loadinfo) } if (loadinfo->base == (void *)-1) { prom_printf("Claim error, can't allocate kernel memory\n"); - return 0; + goto bail; } DEBUG_F("After ELF parsing, load base: %p, mem_sz: 0x%08lx\n", @@ -1192,13 +1192,13 @@ load_elf32(struct boot_file_t *file, loadinfo_t *loadinfo) if ((*(file->fs->seek))(file, p->p_offset) != FILE_ERR_OK) { prom_printf ("Seek error\n"); prom_release(loadinfo->base, loadinfo->memsize); - return 0; + goto bail; } offset = p->p_vaddr - loadinfo->load_loc; if ((*(file->fs->read))(file, p->p_filesz, loadinfo->base+offset) != p->p_filesz) { prom_printf ("Read failed\n"); prom_release(loadinfo->base, loadinfo->memsize); - return 0; + goto bail; } } @@ -1206,6 +1206,11 @@ load_elf32(struct boot_file_t *file, loadinfo_t *loadinfo) /* Return success at loading the Elf32 kernel */ return 1; + +bail: + if (ph) + free(ph); + return 0; } static int @@ -1220,7 +1225,7 @@ load_elf64(struct boot_file_t *file, loadinfo_t *loadinfo) /* Read the rest of the Elf header... */ if ((*(file->fs->read))(file, size, &e->e_version) < size) { prom_printf("\nCan't read Elf64 image header\n"); - return 0; + goto bail; } DEBUG_F("Elf64 header:\n"); @@ -1239,24 +1244,24 @@ load_elf64(struct boot_file_t *file, loadinfo_t *loadinfo) if (e->e_phnum > MAX_HEADERS) { prom_printf ("Can only load kernels with one program header\n"); - return 0; + goto bail; } ph = (Elf64_Phdr *)malloc(sizeof(Elf64_Phdr) * e->e_phnum); if (!ph) { prom_printf ("Malloc error\n"); - return 0; + goto bail; } /* Now, we read the section header */ if ((*(file->fs->seek))(file, e->e_phoff) != FILE_ERR_OK) { prom_printf ("Seek error\n"); - return 0; + goto bail; } if ((*(file->fs->read))(file, sizeof(Elf64_Phdr) * e->e_phnum, ph) != sizeof(Elf64_Phdr) * e->e_phnum) { prom_printf ("Read error\n"); - return 0; + goto bail; } /* Scan through the program header @@ -1283,7 +1288,7 @@ load_elf64(struct boot_file_t *file, loadinfo_t *loadinfo) if (loadinfo->memsize == 0) { prom_printf("Can't find a loadable segment !\n"); - return 0; + goto bail; } /* leave some room (1Mb) for boot infos */ @@ -1312,7 +1317,7 @@ load_elf64(struct boot_file_t *file, loadinfo_t *loadinfo) } if (loadinfo->base == (void *)-1) { prom_printf("Claim error, can't allocate kernel memory\n"); - return 0; + goto bail; } DEBUG_F("After ELF parsing, load base: %p, mem_sz: 0x%08lx\n", @@ -1331,13 +1336,13 @@ load_elf64(struct boot_file_t *file, loadinfo_t *loadinfo) if ((*(file->fs->seek))(file, p->p_offset) != FILE_ERR_OK) { prom_printf ("Seek error\n"); prom_release(loadinfo->base, loadinfo->memsize); - return 0; + goto bail; } offset = p->p_vaddr - loadinfo->load_loc; if ((*(file->fs->read))(file, p->p_filesz, loadinfo->base+offset) != p->p_filesz) { prom_printf ("Read failed\n"); prom_release(loadinfo->base, loadinfo->memsize); - return 0; + goto bail; } } @@ -1345,6 +1350,11 @@ load_elf64(struct boot_file_t *file, loadinfo_t *loadinfo) /* Return success at loading the Elf64 kernel */ return 1; + +bail: + if (ph) + free(ph); + return 0; } static int @@ -1521,11 +1531,13 @@ yaboot_main(void) if ((ptype != NULL) && (strcmp(ptype, "Apple_Bootstrap"))) prom_printf("\nWARNING: Bootstrap partition type is wrong: \"%s\"\n" " type should be: \"Apple_Bootstrap\"\n\n", ptype); + if (ptype) + free(ptype); } } yaboot_text_ui(); - + prom_printf("Bye.\n"); return 0; } -- 2.39.2