Skip to content

Commit

Permalink
core: more updates on mem handling
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Oct 19, 2016
1 parent 377ae93 commit 7d9202f
Show file tree
Hide file tree
Showing 23 changed files with 150 additions and 148 deletions.
5 changes: 3 additions & 2 deletions include/fluent-bit/flb_thread_pthreads.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <pthread.h>

#include <fluent-bit/flb_info.h>
#include <fluent-bit/flb_mem.h>
#include <fluent-bit/flb_macros.h>
#include <fluent-bit/flb_input.h>
#include <fluent-bit/flb_task.h>
Expand Down Expand Up @@ -85,7 +86,7 @@ static struct flb_thread *flb_thread_new()
{
struct flb_thread *th;

th = (struct flb_thread *) malloc(sizeof(struct flb_thread));
th = (struct flb_thread *) flb_malloc(sizeof(struct flb_thread));
if (!th) {
perror("malloc");
return NULL;
Expand Down Expand Up @@ -137,7 +138,7 @@ static FLB_INLINE void flb_thread_destroy(struct flb_thread *th)
*/
#endif

free(th);
flb_free(th);
}

void flb_thread_resume(struct flb_thread *th);
Expand Down
7 changes: 4 additions & 3 deletions include/fluent-bit/flb_thread_ucontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define FLB_THREAD_UCONTEXT_H

#include <fluent-bit/flb_info.h>
#include <fluent-bit/flb_mem.h>
#include <fluent-bit/flb_macros.h>
#include <fluent-bit/flb_log.h>

Expand Down Expand Up @@ -80,7 +81,7 @@ static FLB_INLINE void flb_thread_destroy(struct flb_thread *th)
VALGRIND_STACK_DEREGISTER(th->valgrind_stack_id);
#endif

free(th);
flb_free(th);
}

static FLB_INLINE void flb_thread_resume(struct flb_thread *th)
Expand Down Expand Up @@ -108,7 +109,7 @@ static struct flb_thread *flb_thread_new(size_t data_size,
struct flb_thread *th;

/* Create a thread context and initialize */
p = malloc(sizeof(struct flb_thread) + FLB_THREAD_STACK_SIZE + data_size);
p = flb_malloc(sizeof(struct flb_thread) + FLB_THREAD_STACK_SIZE + data_size);
if (!p) {
flb_errno();
return NULL;
Expand All @@ -120,7 +121,7 @@ static struct flb_thread *flb_thread_new(size_t data_size,
ret = getcontext(&th->callee);
if (ret == -1) {
flb_errno();
free(th);
flb_free(th);
return NULL;
}

Expand Down
12 changes: 6 additions & 6 deletions src/flb_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ static void flb_buffer_worker_init(void *arg)
filename, routes, ctx);
if (ret == -1) {
printf("[buffer] could not create request %s\n", filename);
free(filename);
flb_free(filename);
continue;
}
}
free(filename);
flb_free(filename);
}
else if (event->type == FLB_BUFFER_EV_DEL) {
flb_buffer_chunk_delete(ctx, event);
Expand Down Expand Up @@ -236,13 +236,13 @@ void flb_buffer_destroy(struct flb_buffer *ctx)
mk_event_loop_destroy(worker->evl);
}
mk_list_del(&worker->_head);
free(worker);
flb_free(worker);
}

mk_list_del(&ctx->i_ins->_head);
free(ctx->i_ins);
free(ctx->path);
free(ctx);
flb_free(ctx->i_ins);
flb_free(ctx->path);
flb_free(ctx);
}

/* Check that a directory exists and have write access, if not, create it */
Expand Down
58 changes: 29 additions & 29 deletions src/flb_buffer_chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ int chunk_info(char *filename, struct chunk_info *info)
void request_destroy(struct flb_buffer_request *req)
{
mk_list_del(&req->_head);
free(req);
flb_free(req);
}

/* Given a chunk Hash and a root directory, lookup the absolute path if found */
Expand Down Expand Up @@ -215,13 +215,13 @@ static int chunk_find(char *root_path, char *hash,
root_len = strlen(root_path);
file_len = strlen(file);
if ((file_len + root_len + 1) > PATH_MAX) {
free(file);
flb_free(file);
return -1;
}

target = flb_malloc(PATH_MAX);
if (!target) {
free(file);
flb_free(file);
return -1;
}

Expand Down Expand Up @@ -284,10 +284,10 @@ static int chunk_remove_route(char *root_path, char *abs_path,
ret = rename(abs_path, to);
if (ret == -1) {
flb_errno();
free(to);
flb_free(to);
return -1;
}
free(to);
flb_free(to);

return 0;
}
Expand Down Expand Up @@ -317,14 +317,14 @@ static int chunk_miss(struct flb_buffer_worker *worker, uint64_t mask_id,
ret = chunk_info(real_name, &info);
if (ret != 0) {
flb_error("[buffer] invalid chunk name %s", real_name);
free(real_name);
free(target);
flb_free(real_name);
flb_free(target);
return -1;
}

chunk_remove_route(root_path, target, hash_hex, &info, mask_id);
free(real_name);
free(target);
flb_free(real_name);
flb_free(target);
return 0;
}

Expand All @@ -338,13 +338,13 @@ static int chunk_miss(struct flb_buffer_worker *worker, uint64_t mask_id,
ret = chunk_info(real_name, &info);
if (ret != 0) {
flb_error("[buffer] invalid chunk name %s", real_name);
free(real_name);
free(target);
flb_free(real_name);
flb_free(target);
return -1;
}
chunk_remove_route(root_path, target, hash_hex, &info, mask_id);
free(real_name);
free(target);
flb_free(real_name);
flb_free(target);
}

return 0;
Expand Down Expand Up @@ -399,7 +399,7 @@ int flb_buffer_chunk_add(struct flb_buffer_worker *worker,
worker->id, chunk.tmp);
if (ret == -1) {
flb_errno();
free(fchunk);
flb_free(fchunk);
return -1;
}

Expand All @@ -408,14 +408,14 @@ int flb_buffer_chunk_add(struct flb_buffer_worker *worker,
FLB_BUFFER_PATH(worker), fchunk);
if (ret == -1) {
flb_errno();
free(fchunk);
flb_free(fchunk);
return -1;
}

f = fopen(target, "w");
if (!f) {
flb_errno();
free(fchunk);
flb_free(fchunk);
return -1;
}

Expand All @@ -425,7 +425,7 @@ int flb_buffer_chunk_add(struct flb_buffer_worker *worker,
if (ret == -1) {
flb_errno();
fclose(f);
free(fchunk);
flb_free(fchunk);
return -1;
}

Expand All @@ -434,7 +434,7 @@ int flb_buffer_chunk_add(struct flb_buffer_worker *worker,
if (!w) {
flb_errno();
fclose(f);
free(fchunk);
flb_free(fchunk);
return -1;
}

Expand All @@ -447,7 +447,7 @@ int flb_buffer_chunk_add(struct flb_buffer_worker *worker,
if (ret == -1) {
fprintf(stderr, "[buffer] chunk check failed %lu/%lu bytes",
st.st_size, chunk.size);
free(fchunk);
flb_free(fchunk);
return -1;
}

Expand Down Expand Up @@ -492,8 +492,8 @@ int flb_buffer_chunk_delete(struct flb_buffer_worker *worker,
/* Get chunk info */
ret = chunk_info(real_name, &info);
if (ret == -1) {
free(target);
free(real_name);
flb_free(target);
flb_free(real_name);
return -1;
}

Expand Down Expand Up @@ -528,14 +528,14 @@ int flb_buffer_chunk_delete(struct flb_buffer_worker *worker,
ret = unlink(path);
if (ret == -1) {
flb_errno();
free(target);
free(real_name);
flb_free(target);
flb_free(real_name);
return -1;
}
}

free(target);
free(real_name);
flb_free(target);
flb_free(real_name);

return 0;
}
Expand Down Expand Up @@ -583,15 +583,15 @@ int flb_buffer_chunk_delete_ref(struct flb_buffer_worker *worker,
if (ret != 0) {
flb_errno();
flb_error("[buffer] cannot delete %s", target);
free(target);
free(real_name);
flb_free(target);
flb_free(real_name);
return FLB_BUFFER_ERROR;
}

flb_debug("[buffer] removing task %s OK", target);

free(real_name);
free(target);
flb_free(real_name);
flb_free(target);

/*
* Every time a buffer chunk reference is deleted, we dispatch a
Expand Down
16 changes: 8 additions & 8 deletions src/flb_buffer_qchunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ int flb_buffer_qchunk_delete(struct flb_buffer_qchunk *qchunk)
if (qchunk->id > 0) {
munmap(qchunk->data, qchunk->size);
}
free(qchunk->file_path);
flb_free(qchunk->file_path);
mk_list_del(&qchunk->_head);
free(qchunk);
flb_free(qchunk);

return 0;
}
Expand Down Expand Up @@ -194,7 +194,7 @@ static inline int qchunk_event_push_request(struct flb_buffer *ctx)
/* Obtain an ID for this qchunk */
id = qchunk_get_id(qw);
if (id == -1) {
free(buf);
flb_free(buf);
flb_error("[buffer qchunk] unvailable IDs / max=(1<<14)-1");
continue;
}
Expand All @@ -220,7 +220,7 @@ static inline int qchunk_event_push_request(struct flb_buffer *ctx)
if (ret == -1) {
perror("write");
flb_error("[buffer qchunk] could not notify engine");
free(buf);
flb_free(buf);
continue;
}
return ret;
Expand Down Expand Up @@ -355,7 +355,7 @@ int flb_buffer_qchunk_create(struct flb_buffer *ctx)
/* Create an event loop */
qw->evl = mk_event_loop_create(16);
if (!qw->evl) {
free(qw);
flb_free(qw);
return -1;
}

Expand All @@ -367,7 +367,7 @@ int flb_buffer_qchunk_create(struct flb_buffer *ctx)
if (ret != 0) {
flb_error("[buffer qchunk] could not create manager channels");
mk_event_loop_destroy(qw->evl);
free(qw);
flb_free(qw);
return -1;
}

Expand All @@ -391,7 +391,7 @@ void flb_buffer_qchunk_destroy(struct flb_buffer *ctx)
}

mk_event_loop_destroy(qw->evl);
free(qw);
flb_free(qw);
ctx->qworker = NULL;

return;
Expand Down Expand Up @@ -421,7 +421,7 @@ int flb_buffer_qchunk_start(struct flb_buffer *ctx)
flb_warn("[buffer qchunk] could not spawn worker");
pthread_mutex_unlock(&pth_mutex);
mk_event_loop_destroy(qw->evl);
free(qw);
flb_free(qw);
return -1;
}

Expand Down
16 changes: 8 additions & 8 deletions src/flb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,16 @@ void flb_config_exit(struct flb_config *config)
struct flb_input_collector *collector;

if (config->logfile) {
free(config->logfile);
flb_free(config->logfile);
}

if (config->log) {
flb_log_stop(config->log, config);
}

if (config->kernel) {
free(config->kernel->s_version.data);
free(config->kernel);
flb_free(config->kernel->s_version.data);
flb_free(config->kernel);
}

/* release resources */
Expand Down Expand Up @@ -185,7 +185,7 @@ void flb_config_exit(struct flb_config *config)
}

mk_list_del(&collector->_head);
free(collector);
flb_free(collector);
}

/* Workers */
Expand All @@ -200,7 +200,7 @@ void flb_config_exit(struct flb_config *config)

#ifdef FLB_HAVE_HTTP
if (config->http_port) {
free(config->http_port);
flb_free(config->http_port);
}
#endif

Expand All @@ -209,11 +209,11 @@ void flb_config_exit(struct flb_config *config)
#endif

#ifdef FLB_HAVE_BUFFERING
free(config->buffer_path);
flb_free(config->buffer_path);
#endif

mk_event_loop_destroy(config->evl);
free(config);
flb_free(config);
}

char *flb_config_prop_get(char *key, struct mk_list *list)
Expand Down Expand Up @@ -307,7 +307,7 @@ int flb_config_set_property(struct flb_config *config,
case FLB_CONF_TYPE_STR:
s_val = (char**)((char*)config+service_configs[i].offset);
if ( *s_val != NULL ) {
free(*s_val); /* release before overwriting */
flb_free(*s_val); /* release before overwriting */
}
*s_val = strdup(v);
break;
Expand Down
Loading

0 comments on commit 7d9202f

Please sign in to comment.