sys-assert: Fix handle leak of mmap 47/123347/1 accepted/tizen/unified/20170406.055541 submit/tizen/20170405.094846
authorSunmin Lee <sunm.lee@samsung.com>
Wed, 5 Apr 2017 07:53:29 +0000 (16:53 +0900)
committerSunmin Lee <sunm.lee@samsung.com>
Wed, 5 Apr 2017 08:22:37 +0000 (17:22 +0900)
Unmap the memory after using it if it was mmaped.

Change-Id: Ia567c165ac09308a57ae8bb5eac4a9a2a524ec15
Signed-off-by: Sunmin Lee <sunm.lee@samsung.com>
src/sys-assert/sys-assert.c

index 212e966..63f362e 100644 (file)
@@ -112,6 +112,7 @@ static int trace_symbols(void *const *array, int size, struct addr_node *start,
        unsigned int symtab_index = 0;
        int num_st = 0;
        int found_symtab = 0;
+       int is_mapped = 0;
 
        for (cnt = 0; cnt < size; cnt++) {
                num_st = 0;
@@ -276,6 +277,7 @@ static int trace_symbols(void *const *array, int size, struct addr_node *start,
                                                                (void *)mmap(0, FUNC_NAME_MAX_LEN,
                                                                        PROT_READ | PROT_WRITE,
                                                                        MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+                                                       is_mapped = 1;
                                                        ret = read(file, (void *)info_funcs.dli_sname,
                                                                        FUNC_NAME_MAX_LEN);
                                                        if (ret < 0)
@@ -304,6 +306,8 @@ static int trace_symbols(void *const *array, int size, struct addr_node *start,
                                                cnt, info_funcs.dli_sname,
                                                (info_funcs.dli_saddr - array[cnt]),
                                                array[cnt], info_funcs.dli_fname, offset_addr);
+                       if (is_mapped)
+                               munmap((void *)info_funcs.dli_sname, FUNC_NAME_MAX_LEN);
                } else {
                        fprintf_fd(fd, "%2d: (%p) [%s] + %p\n",
                                        cnt, array[cnt], info_funcs.dli_fname, offset_addr);