src/
2007-10-04  Roland McGrath  <roland@redhat.com>

	* readelf.c (print_archive_index): New variable.
	(options, parse_opt): Accept -c/--archive-index to set it.
	(dump_archive_index): New function.
	(process_file): Take new arg WILL_PRINT_ARCHIVE_INDEX.
	Call dump_archive_index on archives if set.
	(main): Update caller.
	(any_control_option): Give it file scope, moved out of ...
	(parse_opt): ... here.

tests/
2007-10-04  Roland McGrath  <roland@redhat.com>

	* run-readelf-test4.sh: New file.
	* Makefile.am (TESTS, EXTRA_DIST): Add it.

diff --git a/libelf/elf_end.c b/libelf/elf_end.c
index 4b4e11f..5112eae 100644
--- a/libelf/elf_end.c
+++ b/libelf/elf_end.c
@@ -1,5 +1,5 @@
 /* Free resources associated with Elf descriptor.
-   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005 Red Hat, Inc.
+   Copyright (C) 1998,1999,2000,2001,2002,2004,2005,2007 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 1998.
 
@@ -89,7 +89,8 @@
 	 descriptor.  The long name table cannot be freed yet since
 	 the archive headers for the ELF files in the archive point
 	 into this array.  */
-      free (elf->state.ar.ar_sym);
+      if (elf->state.ar.ar_sym != (Elf_Arsym *) -1l)
+	free (elf->state.ar.ar_sym);
       elf->state.ar.ar_sym = NULL;
 
       if (elf->state.ar.children != NULL)
@@ -134,6 +135,21 @@
 
     case ELF_K_ELF:
       {
+	Elf_Data_Chunk *rawchunks
+	  = (elf->class == ELFCLASS32
+	     || (offsetof (struct Elf, state.elf32.rawchunks)
+		 == offsetof (struct Elf, state.elf64.rawchunks))
+	     ? elf->state.elf32.rawchunks
+	     : elf->state.elf64.rawchunks);
+	while (rawchunks != NULL)
+	  {
+	    Elf_Data_Chunk *next = rawchunks->next;
+	    if (rawchunks->dummy_scn.flags & ELF_F_MALLOCED)
+	      free (rawchunks->data.d.d_buf);
+	    free (rawchunks);
+	    rawchunks = next;
+	  }
+
 	Elf_ScnList *list = (elf->class == ELFCLASS32
 			     || (offsetof (struct Elf, state.elf32.scns)
 				 == offsetof (struct Elf, state.elf64.scns))