@@ -82,6 +82,16 @@ struct internal_entry
82
82
SLIST_HEAD (internal_head , internal_entry );
83
83
extern uint32_t (* g_default_hash )(FAR const void * , size_t );
84
84
85
+ /****************************************************************************
86
+ * Private Functions
87
+ ****************************************************************************/
88
+
89
+ static void hfree_r (FAR ENTRY * entry )
90
+ {
91
+ lib_free (entry -> key );
92
+ lib_free (entry -> data );
93
+ }
94
+
85
95
/****************************************************************************
86
96
* Public Functions
87
97
****************************************************************************/
@@ -157,6 +167,11 @@ int hcreate_r(size_t nel, FAR struct hsearch_data *htab)
157
167
SLIST_INIT (& (htab -> htable [idx ]));
158
168
}
159
169
170
+ if (htab -> free_entry == NULL )
171
+ {
172
+ htab -> free_entry = hfree_r ;
173
+ }
174
+
160
175
return 1 ;
161
176
}
162
177
@@ -190,8 +205,7 @@ void hdestroy_r(FAR struct hsearch_data *htab)
190
205
{
191
206
ie = SLIST_FIRST (& (htab -> htable [idx ]));
192
207
SLIST_REMOVE_HEAD (& (htab -> htable [idx ]), link );
193
- lib_free (ie -> ent .key );
194
- lib_free (ie -> ent .data );
208
+ htab -> free_entry (& ie -> ent );
195
209
lib_free (ie );
196
210
}
197
211
}
@@ -245,8 +259,7 @@ int hsearch_r(ENTRY item, ACTION action, FAR ENTRY **retval,
245
259
if (ie != NULL )
246
260
{
247
261
SLIST_REMOVE (head , ie , internal_entry , link );
248
- lib_free (ie -> ent .key );
249
- lib_free (ie -> ent .data );
262
+ htab -> free_entry (& ie -> ent );
250
263
lib_free (ie );
251
264
return 1 ;
252
265
}
0 commit comments