From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Olga Arkhangelskaia <arkholga@tarantool.org>
Cc: tarantool-patches@freelists.org
Subject: Re: [tarantool-patches] [PATCH 2/2] Added strdup fail checks in say
Date: Wed, 18 Jul 2018 15:21:42 +0300 [thread overview]
Message-ID: <20180718122142.o6wngqqzeirb4ezo@esperanza> (raw)
In-Reply-To: <20180717151521.34679-3-arkholga@tarantool.org>
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;
}
prev parent reply other threads:[~2018-07-18 12:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-17 15:15 [tarantool-patches] [PATCH v2 0/2] Refactor in box and say modules Olga Arkhangelskaia
2018-07-17 15:15 ` [tarantool-patches] [PATCH 1/2] Ractoring in string validation of log parametrs Olga Arkhangelskaia
2018-07-18 12:18 ` Vladimir Davydov
2018-07-17 15:15 ` [tarantool-patches] [PATCH 2/2] Added strdup fail checks in say Olga Arkhangelskaia
2018-07-18 12:21 ` Vladimir Davydov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180718122142.o6wngqqzeirb4ezo@esperanza \
--to=vdavydov.dev@gmail.com \
--cc=arkholga@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [tarantool-patches] [PATCH 2/2] Added strdup fail checks in say' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox