[tarantool-patches] [PATCH 2/2] Added strdup fail checks in say
Vladimir Davydov
vdavydov.dev at gmail.com
Wed Jul 18 15:21:42 MSK 2018
On Tue, Jul 17, 2018 at 06:15:21PM +0300, Olga Arkhangelskaia wrote:
> Strdup may silently fail without any message from tarantool.
> Patch adds this checks.
>
> v2:
> there is no v1 for this changes
> ---
> src/say.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/src/say.c b/src/say.c
> index 501095b3e..d824e778b 100644
> --- a/src/say.c
> +++ b/src/say.c
> @@ -498,10 +498,21 @@ log_syslog_init(struct log *log, const char *init_str)
> if (say_parse_syslog_opts(init_str, &opts) < 0)
> return -1;
>
> - if (opts.identity == NULL)
> + if (opts.identity == NULL) {
> log->syslog_ident = strdup("tarantool");
> - else
> + if (log->syslog_ident == NULL) {
> + diag_set(OutOfMemory, strlen("tarantool"), "malloc",
> + "log->syslog_ident");
> + return -1;
> + }
> + } else {
> log->syslog_ident = strdup(opts.identity);
> + if (log->syslog_ident == NULL) {
> + diag_set(OutOfMemory, strlen(opts.identity), "malloc",
> + "log->syslog_ident");
> + return -1;
> + }
> + }
You can avoid code duplication by checking syslog_ident once after
if-else block:
if (opts.identity == NULL)
log->syslog_ident = ...
else
log->syslog_ident = ...
if (log->syslog_ident) {
diag_set(...)
reutrn -1;
}
More information about the Tarantool-patches
mailing list