mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-23 12:42:02 +00:00
add switch_hashtable_insert_destructor so you can insert a pointer into a hash with a custom destructor and use it in spandsp to fix a leak on reloadxml with the tone_descriptor tables and fix a bunch of random tiny leaks etc
This commit is contained in:
@@ -22,6 +22,7 @@ struct entry
|
||||
void *k, *v;
|
||||
unsigned int h;
|
||||
hashtable_flag_t flags;
|
||||
hashtable_destructor_t destructor;
|
||||
struct entry *next;
|
||||
};
|
||||
|
||||
|
||||
@@ -1370,7 +1370,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_destroy(_Inout_ switch_hash_t *
|
||||
\return SWITCH_STATUS_SUCCESS if the data is added
|
||||
\note the string key must be a constant or a dynamic string
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_hash_insert(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ const void *data);
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_destructor(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ const void *data, hashtable_destructor_t destructor);
|
||||
#define switch_core_hash_insert(_h, _k, _d) switch_core_hash_insert_destructor(_h, _k, _d, NULL)
|
||||
|
||||
|
||||
/*!
|
||||
\brief Insert data into a hash
|
||||
|
||||
@@ -123,7 +123,8 @@ typedef enum {
|
||||
} hashtable_flag_t;
|
||||
|
||||
SWITCH_DECLARE(int)
|
||||
switch_hashtable_insert(switch_hashtable_t *h, void *k, void *v, hashtable_flag_t flags);
|
||||
switch_hashtable_insert_destructor(switch_hashtable_t *h, void *k, void *v, hashtable_flag_t flags, hashtable_destructor_t destructor);
|
||||
#define switch_hashtable_insert(_h, _k, _v, _f) switch_hashtable_insert_destructor(_h, _k, _v, _f, NULL)
|
||||
|
||||
#define DEFINE_HASHTABLE_INSERT(fnname, keytype, valuetype) \
|
||||
int fnname (switch_hashtable_t *h, keytype *k, valuetype *v) \
|
||||
|
||||
@@ -2079,6 +2079,8 @@ typedef struct switch_core_port_allocator switch_core_port_allocator_t;
|
||||
typedef struct switch_media_bug switch_media_bug_t;
|
||||
typedef struct switch_limit_interface switch_limit_interface_t;
|
||||
|
||||
typedef void (*hashtable_destructor_t)(void *ptr);
|
||||
|
||||
struct switch_console_callback_match_node {
|
||||
char *val;
|
||||
struct switch_console_callback_match_node *next;
|
||||
|
||||
@@ -875,7 +875,7 @@ SWITCH_DECLARE(switch_time_t) switch_str_time(const char *in);
|
||||
\param vname the name of the global pointer to modify with the new function
|
||||
*/
|
||||
#define SWITCH_DECLARE_GLOBAL_STRING_FUNC(fname, vname) static void fname(const char *string) { if (!string) return;\
|
||||
if (vname) {free(vname); vname = NULL;}vname = strdup(string);} static void fname(const char *string)
|
||||
if (vname) {vname = NULL;}vname = switch_core_permanent_strdup(string);} static void fname(const char *string)
|
||||
|
||||
/*!
|
||||
\brief Separate a string into an array based on a character delimiter
|
||||
|
||||
Reference in New Issue
Block a user