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:
Anthony Minessale
2014-04-09 23:26:41 +05:00
parent d789c6470a
commit 4178688b4a
12 changed files with 56 additions and 37 deletions
@@ -22,6 +22,7 @@ struct entry
void *k, *v;
unsigned int h;
hashtable_flag_t flags;
hashtable_destructor_t destructor;
struct entry *next;
};
+3 -1
View File
@@ -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
+2 -1
View File
@@ -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) \
+2
View File
@@ -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;
+1 -1
View File
@@ -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