Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[StaticScan] Fix resource leak warnings (due to missing dlclose()) by…
… maintaining an array of all dlopen handles and freeing them at ydb_exit() time
- Loading branch information
Showing
12 changed files
with
148 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/**************************************************************** | ||
* * | ||
* Copyright (c) 2018 YottaDB LLC. and/or its subsidiaries. * | ||
* All rights reserved. * | ||
* * | ||
* This source code contains the intellectual property * | ||
* of its copyright holder(s), and is made available * | ||
* under a license. If you do not know the terms of * | ||
* the license, please stop and do not read further. * | ||
* * | ||
****************************************************************/ | ||
|
||
#ifndef DLOPEN_HANDLE_ARRAY_included | ||
#define DLOPEN_HANDLE_ARRAY_included | ||
|
||
void dlopen_handle_array_add(void_ptr_t handle); | ||
void dlopen_handle_array_close(void); | ||
|
||
#endif /* DLOPEN_HANDLE_ARRAY_included */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/**************************************************************** | ||
* * | ||
* Copyright (c) 2018 YottaDB LLC. and/or its subsidiaries. * | ||
* All rights reserved. * | ||
* * | ||
* This source code contains the intellectual property * | ||
* of its copyright holder(s), and is made available * | ||
* under a license. If you do not know the terms of * | ||
* the license, please stop and do not read further. * | ||
* * | ||
****************************************************************/ | ||
|
||
#include "mdef.h" | ||
|
||
#include "gtm_string.h" | ||
|
||
#include "dlopen_handle_array.h" | ||
|
||
GBLREF void_ptr_t *dlopen_handle_array; | ||
GBLREF uint4 dlopen_handle_array_len_alloc; | ||
GBLREF uint4 dlopen_handle_array_len_used; | ||
|
||
void dlopen_handle_array_add(void_ptr_t handle) | ||
{ | ||
void_ptr_t *tmpArray; | ||
|
||
assert(NULL != handle); | ||
assert(dlopen_handle_array_len_used <= dlopen_handle_array_len_alloc); | ||
if (dlopen_handle_array_len_alloc == dlopen_handle_array_len_used) | ||
{ /* No space to hold input handle. Expand array. */ | ||
if (!dlopen_handle_array_len_alloc) | ||
{ /* Nothing allocated till now. Start at 4. Is not too many and yet should avoid expansion in most cases */ | ||
dlopen_handle_array_len_alloc = 4; | ||
} else | ||
dlopen_handle_array_len_alloc *= 2; /* Array already exists. Allocate twice that size. */ | ||
tmpArray = malloc(SIZEOF(void_ptr_t) * dlopen_handle_array_len_alloc); | ||
if (NULL != dlopen_handle_array) | ||
{ | ||
assert(dlopen_handle_array_len_used); | ||
memcpy(tmpArray, dlopen_handle_array, SIZEOF(void_ptr_t) * dlopen_handle_array_len_used); | ||
free(dlopen_handle_array); | ||
} | ||
dlopen_handle_array = tmpArray; | ||
} | ||
dlopen_handle_array[dlopen_handle_array_len_used++] = handle; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/**************************************************************** | ||
* * | ||
* Copyright (c) 2018 YottaDB LLC. and/or its subsidiaries. * | ||
* All rights reserved. * | ||
* * | ||
* This source code contains the intellectual property * | ||
* of its copyright holder(s), and is made available * | ||
* under a license. If you do not know the terms of * | ||
* the license, please stop and do not read further. * | ||
* * | ||
****************************************************************/ | ||
|
||
#include "mdef.h" | ||
|
||
#include <dlfcn.h> | ||
|
||
#include "dlopen_handle_array.h" | ||
|
||
GBLREF void_ptr_t *dlopen_handle_array; | ||
GBLREF uint4 dlopen_handle_array_len_alloc; | ||
GBLREF uint4 dlopen_handle_array_len_used; | ||
|
||
void dlopen_handle_array_close(void) | ||
{ | ||
void_ptr_t handle; | ||
int i, status; | ||
|
||
assert(dlopen_handle_array_len_used <= dlopen_handle_array_len_alloc); | ||
for (i = 0; i < dlopen_handle_array_len_used; i++) | ||
{ | ||
handle = dlopen_handle_array[i]; | ||
assert(NULL != handle); | ||
status = dlclose(handle); | ||
assert(0 == status); | ||
/* Not much we can do in case of an error in "dlclose" while we are already in "ydb_exit". Silently ignore. */ | ||
} | ||
/* Reset globals so they can be used afresh in case another "ydb_init" happens in the same process. */ | ||
if (NULL != dlopen_handle_array) | ||
{ | ||
free(dlopen_handle_array); | ||
dlopen_handle_array = NULL; | ||
} | ||
dlopen_handle_array_len_alloc = 0; | ||
dlopen_handle_array_len_used = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters