From 5575c4249751fb0ef06a4515b612a9286a95cbf3 Mon Sep 17 00:00:00 2001 From: Jeesun Kim Date: Wed, 27 May 2015 14:30:42 +0900 Subject: [PATCH] added error log for calloc Change-Id: I43f29a424ae6ddc290eb0c0c0c9ecb180b4e0e61 --- LICENSE.APLv2 | 2 +- NOTICE | 2 +- include/pims-ipc-data.h | 2 +- include/pims-ipc-svc.h | 2 +- include/pims-ipc-types.h | 2 +- include/pims-ipc.h | 2 +- src/pims-debug.h | 2 +- src/pims-internal.h | 2 +- src/pims-ipc-data-internal.h | 2 +- src/pims-ipc-data.c | 19 ++++++++++- src/pims-ipc-svc.c | 81 ++++++++++++++++++++++++++++++++++++++++---- src/pims-ipc.c | 26 ++++++++++++-- src/pims-socket.c | 2 +- src/pims-socket.h | 2 +- 14 files changed, 126 insertions(+), 22 deletions(-) diff --git a/LICENSE.APLv2 b/LICENSE.APLv2 index 311e5ba..2a14afe 100644 --- a/LICENSE.APLv2 +++ b/LICENSE.APLv2 @@ -1,4 +1,4 @@ -Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. +Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved. Apache License Version 2.0, January 2004 diff --git a/NOTICE b/NOTICE index d34af37..ce761e0 100644 --- a/NOTICE +++ b/NOTICE @@ -1 +1 @@ -Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. +Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved. diff --git a/include/pims-ipc-data.h b/include/pims-ipc-data.h index 8d664de..1b0c6f2 100644 --- a/include/pims-ipc-data.h +++ b/include/pims-ipc-data.h @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. diff --git a/include/pims-ipc-svc.h b/include/pims-ipc-svc.h index 87410d7..f187411 100644 --- a/include/pims-ipc-svc.h +++ b/include/pims-ipc-svc.h @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. diff --git a/include/pims-ipc-types.h b/include/pims-ipc-types.h index 9ea5390..cc0be74 100644 --- a/include/pims-ipc-types.h +++ b/include/pims-ipc-types.h @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. diff --git a/include/pims-ipc.h b/include/pims-ipc.h index b8ba2a5..67de476 100644 --- a/include/pims-ipc.h +++ b/include/pims-ipc.h @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. diff --git a/src/pims-debug.h b/src/pims-debug.h index d8eaa84..d320160 100644 --- a/src/pims-debug.h +++ b/src/pims-debug.h @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. diff --git a/src/pims-internal.h b/src/pims-internal.h index fbc2b42..5034e63 100644 --- a/src/pims-internal.h +++ b/src/pims-internal.h @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. diff --git a/src/pims-ipc-data-internal.h b/src/pims-ipc-data-internal.h index ba947c0..329e953 100644 --- a/src/pims-ipc-data-internal.h +++ b/src/pims-ipc-data-internal.h @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. diff --git a/src/pims-ipc-data.c b/src/pims-ipc-data.c index 9f1c487..4d9662b 100644 --- a/src/pims-ipc-data.c +++ b/src/pims-ipc-data.c @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -55,10 +55,19 @@ API pims_ipc_data_h pims_ipc_data_create_with_size(unsigned int size, int flags) pims_ipc_data_s *handle = NULL; handle = calloc(1, sizeof(pims_ipc_data_s)); + if (NULL == handle) { + ERROR("calloc() Fail"); + return NULL; + } handle->alloc_size = size; handle->free_size = size; handle->buf_size = 0; handle->buf = calloc(1, size); + if (NULL == handle->buf) { + ERROR("calloc() Fail"); + free(handle); + return NULL; + } handle->pos = handle->buf; handle->created = 1; handle->buf_alloced = 1; @@ -115,6 +124,10 @@ API int pims_ipc_data_put(pims_ipc_data_h data, void *buf, unsigned int size) while (new_size < handle->buf_size + used_size) new_size *= 2; handle->buf = realloc(handle->buf, new_size); + if (NULL == handle->buf) { + ERROR("realloc() Fail"); + return -1; + } handle->alloc_size = new_size; handle->free_size = handle->alloc_size - handle->buf_size; handle->pos = handle->buf; @@ -185,6 +198,10 @@ pims_ipc_data_h pims_ipc_data_steal_unmarshal(void *buf, unsigned int size) VERBOSE("size : %d", size); handle = calloc(1, sizeof(pims_ipc_data_s)); + if (NULL == handle) { + ERROR("calloc() Fail"); + return NULL; + } handle->alloc_size = size; handle->free_size = 0; handle->buf_size = handle->alloc_size; diff --git a/src/pims-ipc-svc.c b/src/pims-ipc-svc.c index 925335d..90e382d 100644 --- a/src/pims-ipc-svc.c +++ b/src/pims-ipc-svc.c @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -463,10 +463,19 @@ static void __run_callback(int worker_id, char *call_id, pims_ipc_data_h dhandle cb_data->callback((pims_ipc_h)worker_id, dhandle_in, dhandle_out, cb_data->user_data); } -static void __make_raw_data(const char *call_id, int seq_no, pims_ipc_data_h data, pims_ipc_raw_data_s**out) +static void __make_raw_data(const char *call_id, int seq_no, pims_ipc_data_h data, pims_ipc_raw_data_s **out) { + if (NULL == out) { + ERROR("Invalid parameter:out is NULL"); + return; + } + pims_ipc_raw_data_s *raw_data = NULL; raw_data = (pims_ipc_raw_data_s*)calloc(1, sizeof(pims_ipc_raw_data_s)); + if (NULL == raw_data) { + ERROR("calloc() Fail"); + return; + } pims_ipc_data_s *data_in = (pims_ipc_data_s*)data; raw_data->call_id = strdup(call_id); @@ -476,6 +485,12 @@ static void __make_raw_data(const char *call_id, int seq_no, pims_ipc_data_h dat if (data_in && data_in->buf_size > 0) { raw_data->is_data = TRUE; raw_data->data = calloc(1, data_in->buf_size+1); + if (NULL == raw_data->data) { + ERROR("calloc() Fail"); + free(raw_data->call_id); + free(raw_data); + return; + } memcpy(raw_data->data, data_in->buf, data_in->buf_size); raw_data->data_len = data_in->buf_size; } @@ -590,6 +605,11 @@ static void* __worker_loop(void *data) worker_id = (int)pthread_self(); worker_data = calloc(1, sizeof(pims_ipc_worker_data_s)); + if (NULL == worker_data) { + ERROR("calloc() Fail"); + close(worker_fd); + return NULL; + } worker_data->fd = worker_fd; worker_data->worker_id = worker_id; worker_data->client_fd = -1; @@ -607,7 +627,14 @@ static void* __worker_loop(void *data) write_command(ipc_svc->manager, 1); DEBUG("worker register to manager : worker_id(%08x00), worker_fd(%d)\n", worker_id, worker_fd); - struct pollfd *pollfds = (struct pollfd*) malloc (1 * sizeof (struct pollfd)); + struct pollfd *pollfds = (struct pollfd*)calloc(1, sizeof(struct pollfd)); + if (NULL == pollfds) { + ERROR("calloc() Fail"); + g_hash_table_remove(ipc_svc->task_fds, GINT_TO_POINTER(worker_fd)); + free(worker_data); + close(worker_fd); + return NULL; + } pollfds[0].fd = worker_fd; pollfds[0].events = POLLIN; @@ -644,6 +671,10 @@ static void* __worker_loop(void *data) } else { data_in = pims_ipc_data_steal_unmarshal(raw_data->data, raw_data->data_len); + if (NULL == data_in) { + ERROR("pims_ipc_data_steal_unmarshal() Fail"); + break; + } raw_data->data = NULL; raw_data->data_len = 0; raw_data->is_data = false; @@ -1089,6 +1120,11 @@ static void __request_push(pims_ipc_svc_s *ipc_svc, char *client_id, int client_ } else { data_queue = calloc(1, sizeof(pims_ipc_request_s)); + if (NULL == data_queue) { + ERROR("calloc() Fail"); + pthread_mutex_unlock(&ipc_svc->request_data_queue_mutex); + return; + } data_queue->request_count = 0; pthread_mutex_init(&data_queue->raw_data_mutex, 0); @@ -1193,6 +1229,10 @@ static int __recv_raw_data(int fd, pims_ipc_raw_data_s **data, bool *identity) } temp = (pims_ipc_raw_data_s*)calloc(1, sizeof(pims_ipc_raw_data_s)); + if (NULL == temp) { + ERROR("calloc() Fail"); + return -1; + } temp->client_id = NULL; temp->client_id_len = 0; temp->call_id = NULL; @@ -1219,6 +1259,11 @@ static int __recv_raw_data(int fd, pims_ipc_raw_data_s **data, bool *identity) read_len += ret; temp->client_id = calloc(1, temp->client_id_len+1); + if (NULL == temp->client_id) { + ERROR("calloc() Fail"); + ret = -1; + break; + } ret = socket_recv(fd, (void *)&(temp->client_id), temp->client_id_len); if (ret < 0) { ERROR("socket_recv error"); break; } read_len += ret; @@ -1240,6 +1285,11 @@ static int __recv_raw_data(int fd, pims_ipc_raw_data_s **data, bool *identity) read_len += ret; temp->call_id = calloc(1, temp->call_id_len+1); + if (NULL == temp->call_id) { + ERROR("calloc() Fail"); + ret = -1; + break; + } ret = socket_recv(fd, (void *)&(temp->call_id), temp->call_id_len); if (ret < 0) { ERROR("socket_recv error"); break; } read_len += ret; @@ -1257,6 +1307,11 @@ static int __recv_raw_data(int fd, pims_ipc_raw_data_s **data, bool *identity) read_len += ret; temp->data = calloc(1, temp->data_len+1); + if (NULL == temp->data) { + ERROR("calloc() Fail"); + ret = -1; + break; + } ret = socket_recv(fd, (void *)&(temp->data), temp->data_len); if (ret < 0) { ERROR("socket_recv error"); break; } read_len += ret; @@ -1266,7 +1321,7 @@ static int __recv_raw_data(int fd, pims_ipc_raw_data_s **data, bool *identity) *data = temp; *identity = false; - }while(0); + } while(0); if (ret < 0) { __free_raw_data(temp); @@ -1319,6 +1374,12 @@ static gboolean __request_handler(GIOChannel *src, GIOCondition condition, gpoin // send command to router if (identity) { pims_ipc_client_map_s *client = (pims_ipc_client_map_s*)calloc(1, sizeof(pims_ipc_client_map_s)); + if (NULL == client) { + ERROR("calloc() Fail"); + close(event_fd); + return FALSE; + } + client->fd = event_fd; char temp[100]; @@ -1333,8 +1394,11 @@ static gboolean __request_handler(GIOChannel *src, GIOCondition condition, gpoin ret = __send_identify(event_fd, req->seq_no, temp, strlen(temp)); __free_raw_data(req); - if (ret < 0) + if (ret < 0) { + ERROR("__send_identify() Fail(%d)", ret); + close(event_fd); return FALSE; + } pims_ipc_client_info_s *client_info = NULL; if (0 != _create_client_info(event_fd, &client_info)) @@ -1590,8 +1654,11 @@ static void* __router_loop(void *data) int fd_count = 2; struct pollfd *pollfds; - pollfds = (struct pollfd*) malloc (fd_count * sizeof (struct pollfd)); - + pollfds = (struct pollfd*)calloc(fd_count, sizeof(struct pollfd)); + if (NULL == pollfds) { + ERROR("calloc() Fail"); + return NULL; + } pollfds[0].fd = ipc_svc->router; pollfds[0].events = POLLIN; pollfds[1].fd = ipc_svc->manager; diff --git a/src/pims-ipc.c b/src/pims-ipc.c index 3529476..3292b3a 100644 --- a/src/pims-ipc.c +++ b/src/pims-ipc.c @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -311,6 +311,10 @@ static int __pims_ipc_read_data(pims_ipc_s *handle, pims_ipc_data_h *data_out) if (total_len == read_len) { // send identity data = pims_ipc_data_create(0); + if (NULL == data) { + ERROR("pims_ipc_data_create() Fail"); + break; + } ret = pims_ipc_data_put(data, client_id, client_id_len); if (ret != 0) WARNING("pims_ipc_data_put fail(%d)", ret); @@ -350,6 +354,10 @@ static int __pims_ipc_read_data(pims_ipc_s *handle, pims_ipc_data_h *data_out) read_len += ret; data = pims_ipc_data_steal_unmarshal(buf, data_len); + if (NULL == data) { + ERROR("pims_ipc_data_steal_unmarshal() Fail"); + break; + } buf = NULL; } @@ -382,7 +390,11 @@ static int __pims_ipc_read_data(pims_ipc_s *handle, pims_ipc_data_h *data_out) static int __pims_ipc_receive(pims_ipc_s *handle, pims_ipc_data_h *data_out) { int ret = -1; - struct pollfd *pollfds = (struct pollfd*) malloc (1 * sizeof (struct pollfd)); + struct pollfd *pollfds = (struct pollfd*)calloc(1, sizeof(struct pollfd)); + if (NULL == pollfds) { + ERROR("calloc() Fail"); + return -1; + } pollfds[0].fd = handle->fd; pollfds[0].events = POLLIN | POLLERR | POLLHUP; @@ -500,9 +512,17 @@ static int __subscribe_data(pims_ipc_s * handle) read_len += ret; dhandle = pims_ipc_data_steal_unmarshal(buf, data_len); + if (NULL == dhandle) { + ERROR("pims_ipc_data_steal_unmarshal() Fail"); + break; + } buf = NULL; pims_ipc_subscribe_data_s *sub_data = (pims_ipc_subscribe_data_s *)calloc(1, sizeof(pims_ipc_subscribe_data_s)); + if (NULL == sub_data) { + ERROR("calloc() Fail"); + break; + } sub_data->handle = dhandle; sub_data->call_id = call_id; call_id = NULL; @@ -513,7 +533,7 @@ static int __subscribe_data(pims_ipc_s * handle) write_command(handle->subscribe_fd, 1); } ret = 0; - }while(0); + } while(0); free(call_id); free(buf); diff --git a/src/pims-socket.c b/src/pims-socket.c index eff803d..b1ea166 100644 --- a/src/pims-socket.c +++ b/src/pims-socket.c @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. diff --git a/src/pims-socket.h b/src/pims-socket.h index e3bdb16..d04d1d7 100644 --- a/src/pims-socket.h +++ b/src/pims-socket.h @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. -- 2.7.4