Revision b79c8e3a src/PeerSet/peerset_ops.c

View differences:

src/PeerSet/peerset_ops.c
20 20

  
21 21
#define DEFAULT_SIZE_INCREMENT 32
22 22

  
23
void peer_init_data(struct peer *p)
24
{
25
	if (p)
26
	{
27
		p->metadata = NULL;
28
		p->user_data = NULL;
29
	}
30
}
31

  
32
void peer_deinit_data(struct peer *p)
33
{
34
	if(p && p->metadata)
35
		free(p->metadata);
36
	if(p && p->metadata)
37
		free(p->user_data);
38
}
39

  
40
peer_deinit_f peer_deinit = peer_deinit_data;
41
peer_init_f peer_init = peer_init_data;
42

  
23 43
static int nodeid_peer_cmp(const void *id, const void *p)
24 44
{
25 45
  const struct peer *peer = *(struct peer *const *)p;
......
156 176
  h->elements[pos] = e;
157 177
  gettimeofday(&e->creation_timestamp, NULL);
158 178
  e->id = nodeid_dup(id);
159
  e->metadata = NULL;
160
  e->user_data = NULL;
179
  peer_init(e);
161 180

  
162 181
  return h->n_elements;
163 182
}
......
203 222
  if (i >= 0) {
204 223
    struct peer *e = h->elements[i];
205 224
    nodeid_free(e->id);
206
    if (e->metadata)
207
	    free(e->metadata);
208
    if (e->user_data)
209
	    free(e->user_data);
225
    if (peer_deinit)
226
	    peer_deinit(e);
210 227
    memmove(&h->elements[i], &h->elements[i+1], ((h->n_elements--) - (i+1)) * sizeof(struct peer *));
211 228
    free(e);
212 229

  
......
231 248
  for (i = 0; i < h->n_elements; i++) {
232 249
    struct peer *e = h->elements[i];
233 250
    nodeid_free(e->id);
234
    if (e->metadata)
235
	    free(e->metadata);
236
    if (e->user_data)
237
	    free(e->user_data);
251
    if (peer_deinit)
252
	    peer_deinit(e);
238 253
    free(e);
239 254
  }
240 255

  

Also available in: Unified diff