static void chunk_free(chunk *c) { if (NULL == c) return; chunk_reset(c); buffer_free(c->mem); buffer_free(c->file.name); free(c); }
static void chunk_free(chunk *c) { if (!c) return; /* make sure fd's are closed and tempfile's are deleted. */ chunk_reset(c); buffer_free(c->mem); buffer_free(c->file.name); free(c); }
/** * keep unused chunks alive and store them in the chunkpool * * we only want to keep a small set of chunks alive to balance between * memory-usage and mallocs * * each filter will ask for a chunk */ static void chunkpool_add_unused_chunk(chunk *c) { if (chunkpool_chunks > 128) { chunk_free(c); } else { chunk_reset(c); /* prepend the chunk to the chunkpool */ c->next = chunkpool; chunkpool = c; chunkpool_chunks++; } }
static void chunkqueue_push_unused_chunk(chunkqueue *cq, chunk *c) { force_assert(NULL != cq && NULL != c); /* keep at max 4 chunks in the 'unused'-cache */ if (cq->unused_chunks > 4) { chunk_free(c); } else { chunk_reset(c); c->next = cq->unused; cq->unused = c; cq->unused_chunks++; } }
static int da_haproxy(const struct arg *args, struct sample *smp, da_deviceinfo_t *devinfo) { struct buffer *tmp; da_propid_t prop, *pprop; da_status_t status; da_type_t proptype; const char *propname; int i; tmp = get_trash_chunk(); chunk_reset(tmp); propname = (const char *) args[0].data.str.area; i = 0; for (; propname != 0; i ++, propname = (const char *) args[i].data.str.area) { status = da_atlas_getpropid(&global_deviceatlas.atlas, propname, &prop); if (status != DA_OK) { chunk_appendf(tmp, "%c", global_deviceatlas.separator); continue; } pprop = ∝ da_atlas_getproptype(&global_deviceatlas.atlas, *pprop, &proptype); switch (proptype) { case DA_TYPE_BOOLEAN: { bool val; status = da_getpropboolean(devinfo, *pprop, &val); if (status == DA_OK) { chunk_appendf(tmp, "%d", val); } break; } case DA_TYPE_INTEGER: case DA_TYPE_NUMBER: { long val; status = da_getpropinteger(devinfo, *pprop, &val); if (status == DA_OK) { chunk_appendf(tmp, "%ld", val); } break; } case DA_TYPE_STRING: { const char *val; status = da_getpropstring(devinfo, *pprop, &val); if (status == DA_OK) { chunk_appendf(tmp, "%s", val); } break; } default: break; } chunk_appendf(tmp, "%c", global_deviceatlas.separator); } da_close(devinfo); if (tmp->data) { --tmp->data; tmp->area[tmp->data] = 0; } smp->data.u.str.area = tmp->area; smp->data.u.str.data = tmp->data; return 1; }