-0.29 Wed May 13 08:06:05 PDT 2009
+0.29
+ * Fixed malloc usage to calloc for spots where we need zero filled memory.
* All code warnings now treated as errors.
* Fixes for debian packaging.
* Added new pooling mechanism.
for (x= 0; x < opt_concurrency; x++)
{
thread_context_st *context;
- context= (thread_context_st *)malloc(sizeof(thread_context_st));
- memset(context, 0, sizeof(thread_context_st));
+ context= (thread_context_st *)calloc(1, sizeof(thread_context_st));
context->memc= memcached_clone(NULL, memc);
context->test= opt_test;
=item MEMCACHED_CALLBACK_MALLOC_FUNCTION
This alllows yout to pass in a customized version of malloc that will be used instead of the builtin malloc(3) call.
+Your malloc must zero all memory.
The prototype for this is:
void *(*memcached_malloc_function)(memcached_st *ptr, const size_t size);
if (ptr == NULL)
{
- ptr= (memcached_st *)malloc(sizeof(memcached_st));
+ ptr= (memcached_st *)calloc(1, sizeof(memcached_st));
if (!ptr)
return NULL; /* MEMCACHED_MEMORY_ALLOCATION_FAILURE */
- memset(ptr, 0, sizeof(memcached_st));
ptr->is_allocated= true;
}
else
*error= MEMCACHED_SUCCESS;
server_count= memcached_server_count(memc);
- result= (memcached_analysis_st*)malloc(sizeof(memcached_analysis_st)
+ result= (memcached_analysis_st*)calloc(1, sizeof(memcached_analysis_st)
* (memc->number_of_hosts));
if (!result)
{
return NULL;
}
- memset(result, 0, sizeof(*result));
-
for (x= 0; x < server_count; x++)
{
calc_largest_consumption(result, x, stat[x].bytes);
result_buffer= memcached_fetch_result(ptr, result_buffer, error);
- if (*error != MEMCACHED_SUCCESS || result_buffer == NULL)
+ if (result_buffer == NULL || *error != MEMCACHED_SUCCESS)
{
+ WATCHPOINT_ASSERT(result_buffer == NULL);
*value_length= 0;
return NULL;
}
if ((result= memcached_result_create(ptr, NULL)) == NULL)
return NULL;
- while ((server = memcached_io_get_readable_server(ptr)) != NULL) {
+ while ((server = memcached_io_get_readable_server(ptr)) != NULL)
+ {
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
*error= memcached_response(server, buffer, sizeof(buffer), result);
if (memc->call_malloc)
ptr= (memcached_result_st *)memc->call_malloc(memc, sizeof(memcached_result_st));
else
- ptr= (memcached_result_st *)malloc(sizeof(memcached_result_st));
+ ptr= (memcached_result_st *)calloc(1, sizeof(memcached_result_st));
if (ptr == NULL)
return NULL;
- memset(ptr, 0, sizeof(memcached_result_st));
ptr->is_allocated= true;
}
{
if (ptr == NULL)
{
- ptr= (memcached_server_st *)malloc(sizeof(memcached_server_st));
+ ptr= (memcached_server_st *)calloc(1, sizeof(memcached_server_st));
if (!ptr)
return NULL; /* MEMCACHED_MEMORY_ALLOCATION_FAILURE */
- memset(ptr, 0, sizeof(memcached_server_st));
ptr->is_allocated= true;
}
else
if (ptr->call_malloc)
stats= (memcached_stat_st *)ptr->call_malloc(ptr, sizeof(memcached_stat_st)*(ptr->number_of_hosts));
else
- stats= (memcached_stat_st *)malloc(sizeof(memcached_stat_st)*(ptr->number_of_hosts));
+ stats= (memcached_stat_st *)calloc(1, sizeof(memcached_stat_st)*(ptr->number_of_hosts));
if (!stats)
{
*error= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
return NULL;
}
- memset(stats, 0, sizeof(memcached_stat_st)*(ptr->number_of_hosts));
rc= MEMCACHED_SUCCESS;
for (x= 0; x < ptr->number_of_hosts; x++)
if (ptr->call_malloc)
list= (char **)ptr->call_malloc(ptr, length);
else
- list= (char **)malloc(length);
+ list= (char **)calloc(1, length);
if (!list)
{
*error= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
return NULL;
}
- memset(list, 0, sizeof(memcached_stat_keys));
memcpy(list, memcached_stat_keys, sizeof(memcached_stat_keys));
if (ptr->call_malloc)
string= (memcached_string_st *)ptr->call_malloc(ptr, sizeof(memcached_string_st));
else
- string= (memcached_string_st *)malloc(sizeof(memcached_string_st));
+ string= (memcached_string_st *)calloc(1, sizeof(memcached_string_st));
if (string == NULL)
return NULL;
- memset(string, 0, sizeof(memcached_string_st));
string->is_allocated= true;
}
string->block_size= MEMCACHED_BLOCK_SIZE;
libtool --mode=execute valgrind --tool=callgrind testapp
callgrind_annotate callgrind.out.* --auto=yes > /tmp/callgrind.out
+helgrind:
+ rm -f helgrind.out.*
+ libtool --mode=execute valgrind --tool=helgrind testapp
+
+helgrind-slap:
+ libtool --mode=execute valgrind --tool=helgrind ../clients/memslap --server=localhost --concurrency=30
+
test-no-outputdiff: testapp
./testapp > /dev/null
@echo "Test completed"
static void *my_malloc(memcached_st *ptr __attribute__((unused)), const size_t size)
{
- return malloc(size);
+ return calloc(1, size);
}
static void *my_realloc(memcached_st *ptr __attribute__((unused)), void *mem, const size_t size)