Revision 10ddaca7

View differences:

include/peersampler.h
168 168
*/
169 169
int psample_parse_data(struct psample_context *tc, const uint8_t *buff, int len);
170 170

  
171
void psample_destroy(struct psample_context **context);
171 172
#endif /* PEERSAMPLER_H */
src/Cache/ncast_proto.c
72 72
int ncast_proto_myentry_update(struct ncast_proto_context *context, struct nodeID *s, int dts, const void *meta, int meta_size) {
73 73
  return topo_proto_myentry_update(context->context, s, dts, meta, meta_size);
74 74
}
75

  
76
void ncast_proto_destroy(struct ncast_proto_context ** c)
77
{
78
	if (c && *c)
79
	{
80
		if ((*c)->context)
81
			topo_proto_destroy(&((*c)->context));
82
		free(*c);
83
		*c = NULL;
84
	}
85
}
src/Cache/ncast_proto.h
4 4
struct ncast_proto_context;
5 5

  
6 6
struct ncast_proto_context* ncast_proto_init(struct nodeID *s, const void *meta, int meta_size);
7
void ncast_proto_destroy(struct ncast_proto_context **);
7 8

  
8 9
int ncast_reply(struct ncast_proto_context *context, const struct peer_cache *c, const struct peer_cache *local_cache);
9 10
int ncast_query(struct ncast_proto_context *context, const struct peer_cache *local_cache);
src/Cache/topo_proto.c
156 156

  
157 157
  return con;
158 158
}
159

  
160
void topo_proto_destroy(struct topo_context ** t)
161
{
162
	if (t && *t)
163
	{
164
		if ((*t)->pkt)
165
			free((*t)->pkt);
166
		if ((*t)->myEntry)
167
			cache_free((*t)->myEntry);
168
		free(*t);
169
		*t = NULL;
170
	}
171
}
src/Cache/topo_proto.h
14 14
int topo_proto_metadata_update(struct topo_context *context, const void *meta, int meta_size);
15 15
struct topo_context* topo_proto_init(struct nodeID *s, const void *meta, int meta_size);
16 16

  
17
void topo_proto_destroy(struct topo_context ** t);
18

  
17 19
#endif /* TOPO_PROTO */
src/ChunkBuffer/buffer.c
106 106
    free(cb);
107 107
    return NULL;
108 108
  }
109
  memset(cb->buffer, 0, cb->size);
109
  memset(cb->buffer, 0, sizeof(struct chunk) * cb->size);
110 110
  for (i = 0; i < cb->size; i++) {
111 111
    cb->buffer[i].id = -1;
112 112
  }
src/PeerSampler/cloudcast.c
481 481
  return cloudcast_proto_change_metadata(context->proto_context, metadata, metadata_size);
482 482
}
483 483

  
484
void cloudcast_destroy(struct peersampler_context **context)
485
{
486
	if (context && *context)
487
	{
488
		if((*context)->r)
489
			free((*context)->r);
490
		if((*context)->local_cache)
491
			cache_free((*context)->local_cache);
492
		if((*context)->flying_cache)
493
			cache_free((*context)->flying_cache);
494
		free(*context);
495
		*context = NULL;
496
	}
497
}
498

  
484 499
struct peersampler_iface cloudcast = {
485 500
  .init = cloudcast_init,
501
  .destroy = cloudcast_destroy,
486 502
  .change_metadata = cloudcast_change_metadata,
487 503
  .add_neighbour = cloudcast_add_neighbour,
488 504
  .parse_data = cloudcast_parse_data,
src/PeerSampler/cyclon.c
261 261
  return cyclon_proto_change_metadata(context->pc, metadata, metadata_size);
262 262
}
263 263

  
264
void cyclon_destroy(struct peersampler_context **context)
265
{
266
	if (context && *context)
267
	{
268
		if((*context)->r)
269
			free((*context)->r);
270
		if((*context)->local_cache)
271
			cache_free((*context)->local_cache);
272
		if((*context)->flying_cache)
273
			cache_free((*context)->flying_cache);
274
		free(*context);
275
		*context = NULL;
276
	}
277
}
278

  
264 279
struct peersampler_iface cyclon = {
265 280
  .init = cyclon_init,
281
  .destroy = cyclon_destroy,
266 282
  .change_metadata = cyclon_change_metadata,
267 283
  .add_neighbour = cyclon_add_neighbour,
268 284
  .parse_data = cyclon_parse_data,
src/PeerSampler/dummy.c
107 107
  return -1;
108 108
}
109 109

  
110
void dummy_destroy(struct peersampler_context **context)
111
{
112
	if (context && *context)
113
	{
114
		if((*context)->r)
115
			free((*context)->r);
116
		free(*context);
117
		*context = NULL;
118
	}
119
}
120

  
110 121

  
111 122
struct peersampler_iface dummy = {
112 123
  .init = dummy_init,
124
  .destroy = dummy_destroy,
113 125
  .change_metadata = dummy_change_metadata,
114 126
  .add_neighbour = dummy_add_neighbour,
115 127
  .parse_data = dummy_parse_data,
src/PeerSampler/ncast.c
278 278
  return cache_del(context->local_cache, neighbour);
279 279
}
280 280

  
281
void ncast_destroy(struct peersampler_context **context)
282
{
283
	if (context && *context)
284
	{
285
		if((*context)->r)
286
			free((*context)->r);
287
		if((*context)->local_cache)
288
			cache_free((*context)->local_cache);
289
		if((*context)->tc)
290
			ncast_proto_destroy(&((*context)->tc));
291
		if((*context)->bootstrap_node)
292
			nodeid_free(((*context)->bootstrap_node));
293
		free(*context);
294
		*context = NULL;
295
	}
296
}
297

  
281 298
struct peersampler_iface ncast = {
282 299
  .init = ncast_init,
300
  .destroy = ncast_destroy,
283 301
  .change_metadata = ncast_change_metadata,
284 302
  .add_neighbour = ncast_add_neighbour,
285 303
  .parse_data = ncast_parse_data,
......
292 310

  
293 311
struct peersampler_iface ncastplus = {
294 312
  .init = ncastplus_init,
313
  .destroy = ncast_destroy,
295 314
  .change_metadata = ncast_change_metadata,
296 315
  .add_neighbour = ncast_add_neighbour,
297 316
  .parse_data = ncast_parse_data,
src/PeerSampler/peersampler.c
98 98
{
99 99
  return tc->ps->remove_neighbour(tc->ps_context, neighbour);
100 100
}
101

  
102
void psample_destroy(struct psample_context **tc)
103
{
104
  if (tc && *tc)
105
  {
106
    (*tc)->ps->destroy(&((*tc)->ps_context));
107
    free(*tc);
108
    *tc = NULL;
109
  }
110
}
src/PeerSampler/peersampler_iface.h
13 13
  int (*grow_neighbourhood)(struct peersampler_context *context, int n);
14 14
  int (*shrink_neighbourhood)(struct peersampler_context *context, int n);
15 15
  int (*remove_neighbour)(struct peersampler_context *context, const struct nodeID *neighbour);
16
  void (*destroy)(struct peersampler_context **context);
16 17
};
17 18

  
18 19
#endif	/* PEERSAMPLER_IFACE */
src/PeerSet/peerset_ops.c
236 236

  
237 237
  h->n_elements = 0;
238 238
  h->size = size;
239
  h->elements = realloc(h->elements, size * sizeof(struct peer *));
239
  if (h->size)
240
	  h->elements = realloc(h->elements, size * sizeof(struct peer *));
241
  else
242
  {
243
	  free(h->elements);
244
	  h->elements = NULL;
245
  }
240 246
  if (h->elements == NULL) {
241 247
    h->size = 0;
242 248
  }

Also available in: Unified diff