X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=clients%2Fgenerator.c;h=6e2f27953a5d48c50f88e3a8eb548240c64a386f;hb=ea260e7bce23c9a41c3c60fd68f55b33608714a9;hp=213246ba2206a3d84916c8503c43c089bc26e975;hpb=1b18496b3d1399d90cfba1975f23aee9c747445a;p=m6w6%2Flibmemcached diff --git a/clients/generator.c b/clients/generator.c index 213246ba..6e2f2795 100644 --- a/clients/generator.c +++ b/clients/generator.c @@ -1,3 +1,14 @@ +/* LibMemcached + * Copyright (C) 2006-2009 Brian Aker + * All rights reserved. + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + * + * Summary: + * + */ + #include "libmemcached/common.h" #include @@ -31,14 +42,15 @@ void pairs_free(pairs_st *pairs) { uint32_t x; - if (!pairs) + if (! pairs) return; /* We free until we hit the null pair we stores during creation */ for (x= 0; pairs[x].key; x++) { free(pairs[x].key); - free(pairs[x].value); + if (pairs[x].value) + free(pairs[x].value); } free(pairs); @@ -47,7 +59,9 @@ void pairs_free(pairs_st *pairs) pairs_st *pairs_generate(uint64_t number_of, size_t value_length) { unsigned int x; - pairs_st *pairs= calloc((size_t)(number_of + 1), sizeof(pairs_st)); + pairs_st *pairs; + + pairs= (pairs_st*)calloc((size_t)number_of + 1, sizeof(pairs_st)); if (!pairs) goto error; @@ -60,11 +74,19 @@ pairs_st *pairs_generate(uint64_t number_of, size_t value_length) get_random_string(pairs[x].key, 100); pairs[x].key_length= 100; - pairs[x].value= (char *)calloc(value_length, sizeof(char)); - if (!pairs[x].value) - goto error; - get_random_string(pairs[x].value, value_length); - pairs[x].value_length= value_length; + if (value_length) + { + pairs[x].value= (char *)calloc(value_length, sizeof(char)); + if (!pairs[x].value) + goto error; + get_random_string(pairs[x].value, value_length); + pairs[x].value_length= value_length; + } + else + { + pairs[x].value= NULL; + pairs[x].value_length= 0; + } } return pairs;