X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Fgenerator.c;h=793157ef52666e611b4a8fd3a4bb7732876679bd;hb=604a085089f439ad9c07ace21c36d17d9b620c3b;hp=df04d348faf4e98fbe56a096211ed24e90b2549f;hpb=320638630f5a35ddfc4fe0d571b24016a7a80de7;p=m6w6%2Flibmemcached diff --git a/src/generator.c b/src/generator.c index df04d348..793157ef 100644 --- a/src/generator.c +++ b/src/generator.c @@ -23,6 +23,9 @@ void pairs_free(pairs_st *pairs) { unsigned int x; + if (!pairs) + return; + /* We free until we hit the null pair we stores during creation */ for (x= 0; pairs[x].key; x++) { @@ -33,7 +36,7 @@ void pairs_free(pairs_st *pairs) free(pairs); } -pairs_st *pairs_generate(unsigned long long number_of) +pairs_st *pairs_generate(unsigned long long number_of, size_t value_length) { unsigned int x; pairs_st *pairs; @@ -53,11 +56,11 @@ pairs_st *pairs_generate(unsigned long long number_of) get_random_string(pairs[x].key, 100); pairs[x].key_length= 100; - pairs[x].value= (char *)malloc(sizeof(char) * 400); + pairs[x].value= (char *)malloc(sizeof(char) * value_length); if (!pairs[x].value) goto error; - get_random_string(pairs[x].value, 400); - pairs[x].value_length= 400; + get_random_string(pairs[x].value, value_length); + pairs[x].value_length= value_length; } return pairs;