mirror of
https://github.com/ianlancetaylor/libbacktrace.git
synced 2026-04-06 01:19:07 +08:00
* elf.c (elf_add): Close descriptor if we use a debugfile.
* btest.c (check_open_files): New static function. (main): Call check_open_files.
This commit is contained in:
22
btest.c
22
btest.c
@@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. */
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "filenames.h"
|
#include "filenames.h"
|
||||||
|
|
||||||
@@ -456,6 +457,25 @@ test5 (void)
|
|||||||
return failures;
|
return failures;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check that are no files left open. */
|
||||||
|
|
||||||
|
static void
|
||||||
|
check_open_files (void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 3; i < 10; i++)
|
||||||
|
{
|
||||||
|
if (close (i) == 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr,
|
||||||
|
"ERROR: descriptor %d still open after tests complete\n",
|
||||||
|
i);
|
||||||
|
++failures;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Run all the tests. */
|
/* Run all the tests. */
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -474,5 +494,7 @@ main (int argc ATTRIBUTE_UNUSED, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
check_open_files ();
|
||||||
|
|
||||||
exit (failures ? EXIT_FAILURE : EXIT_SUCCESS);
|
exit (failures ? EXIT_FAILURE : EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|||||||
22
elf.c
22
elf.c
@@ -2929,12 +2929,19 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor,
|
|||||||
error_callback, data);
|
error_callback, data);
|
||||||
if (d >= 0)
|
if (d >= 0)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
backtrace_release_view (state, &buildid_view, error_callback, data);
|
backtrace_release_view (state, &buildid_view, error_callback, data);
|
||||||
if (debuglink_view_valid)
|
if (debuglink_view_valid)
|
||||||
backtrace_release_view (state, &debuglink_view, error_callback,
|
backtrace_release_view (state, &debuglink_view, error_callback,
|
||||||
data);
|
data);
|
||||||
return elf_add (state, NULL, d, base_address, error_callback, data,
|
ret = elf_add (state, NULL, d, base_address, error_callback, data,
|
||||||
fileline_fn, found_sym, found_dwarf, 0, 1);
|
fileline_fn, found_sym, found_dwarf, 0, 1);
|
||||||
|
if (ret < 0)
|
||||||
|
backtrace_close (d, error_callback, data);
|
||||||
|
else
|
||||||
|
backtrace_close (descriptor, error_callback, data);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2953,10 +2960,17 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor,
|
|||||||
data);
|
data);
|
||||||
if (d >= 0)
|
if (d >= 0)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
backtrace_release_view (state, &debuglink_view, error_callback,
|
backtrace_release_view (state, &debuglink_view, error_callback,
|
||||||
data);
|
data);
|
||||||
return elf_add (state, NULL, d, base_address, error_callback, data,
|
ret = elf_add (state, NULL, d, base_address, error_callback, data,
|
||||||
fileline_fn, found_sym, found_dwarf, 0, 1);
|
fileline_fn, found_sym, found_dwarf, 0, 1);
|
||||||
|
if (ret < 0)
|
||||||
|
backtrace_close (d, error_callback, data);
|
||||||
|
else
|
||||||
|
backtrace_close(descriptor, error_callback, data);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user