Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit 1779403

Browse files
* elf.c (elf_add): Close descriptor if we use a debugfile.
* btest.c (check_open_files): New static function. (main): Call check_open_files.
1 parent 811741b commit 1779403

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

btest.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. */
3737
#include <stdio.h>
3838
#include <stdlib.h>
3939
#include <string.h>
40+
#include <unistd.h>
4041

4142
#include "filenames.h"
4243

@@ -456,6 +457,25 @@ test5 (void)
456457
return failures;
457458
}
458459

460+
/* Check that are no files left open. */
461+
462+
static void
463+
check_open_files (void)
464+
{
465+
int i;
466+
467+
for (i = 3; i < 10; i++)
468+
{
469+
if (close (i) == 0)
470+
{
471+
fprintf (stderr,
472+
"ERROR: descriptor %d still open after tests complete\n",
473+
i);
474+
++failures;
475+
}
476+
}
477+
}
478+
459479
/* Run all the tests. */
460480

461481
int
@@ -474,5 +494,7 @@ main (int argc ATTRIBUTE_UNUSED, char **argv)
474494
#endif
475495
#endif
476496

497+
check_open_files ();
498+
477499
exit (failures ? EXIT_FAILURE : EXIT_SUCCESS);
478500
}

elf.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2929,12 +2929,19 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor,
29292929
error_callback, data);
29302930
if (d >= 0)
29312931
{
2932+
int ret;
2933+
29322934
backtrace_release_view (state, &buildid_view, error_callback, data);
29332935
if (debuglink_view_valid)
29342936
backtrace_release_view (state, &debuglink_view, error_callback,
29352937
data);
2936-
return elf_add (state, NULL, d, base_address, error_callback, data,
2937-
fileline_fn, found_sym, found_dwarf, 0, 1);
2938+
ret = elf_add (state, NULL, d, base_address, error_callback, data,
2939+
fileline_fn, found_sym, found_dwarf, 0, 1);
2940+
if (ret < 0)
2941+
backtrace_close (d, error_callback, data);
2942+
else
2943+
backtrace_close (descriptor, error_callback, data);
2944+
return ret;
29382945
}
29392946
}
29402947

@@ -2953,10 +2960,17 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor,
29532960
data);
29542961
if (d >= 0)
29552962
{
2963+
int ret;
2964+
29562965
backtrace_release_view (state, &debuglink_view, error_callback,
29572966
data);
2958-
return elf_add (state, NULL, d, base_address, error_callback, data,
2959-
fileline_fn, found_sym, found_dwarf, 0, 1);
2967+
ret = elf_add (state, NULL, d, base_address, error_callback, data,
2968+
fileline_fn, found_sym, found_dwarf, 0, 1);
2969+
if (ret < 0)
2970+
backtrace_close (d, error_callback, data);
2971+
else
2972+
backtrace_close(descriptor, error_callback, data);
2973+
return ret;
29602974
}
29612975
}
29622976

0 commit comments

Comments
 (0)