Do not leak p if pdu->global != 0.
This is an improvement for a previous attempt to fix handle_job_opt(). See
also commit
ebae36a28aee ("client: Fix memory leaks in handle_job_opt()").
Do not leak strdup(pdu->name) when calling json_object_add_value_string().
That function namely (indirectly) duplicates its 'name' argument.
This patch fixes the following Coverity complaint:
CID 169311 (#1 of 1): Resource leak (RESOURCE_LEAK)
9. leaked_storage: Variable p going out of scope leaks the storage it points to.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
static void handle_job_opt(struct fio_client *client, struct fio_net_cmd *cmd)
{
struct cmd_job_option *pdu = (struct cmd_job_option *) cmd->payload;
static void handle_job_opt(struct fio_client *client, struct fio_net_cmd *cmd)
{
struct cmd_job_option *pdu = (struct cmd_job_option *) cmd->payload;
- struct print_option *p;
if (!job_opt_object)
return;
if (!job_opt_object)
return;
pdu->truncated = le16_to_cpu(pdu->truncated);
pdu->groupid = le32_to_cpu(pdu->groupid);
pdu->truncated = le16_to_cpu(pdu->truncated);
pdu->groupid = le32_to_cpu(pdu->groupid);
- p = malloc(sizeof(*p));
- p->name = strdup((char *) pdu->name);
-
- json_object_add_value_string(job_opt_object, p->name,
+ json_object_add_value_string(job_opt_object,
+ (const char *)pdu->name,
(const char *)pdu->value);
} else if (client->opt_lists) {
struct flist_head *opt_list = &client->opt_lists[pdu->groupid];
(const char *)pdu->value);
} else if (client->opt_lists) {
struct flist_head *opt_list = &client->opt_lists[pdu->groupid];
+ struct print_option *p;
+ p = malloc(sizeof(*p));
+ p->name = strdup((const char *)pdu->name);
p->value = pdu->value[0] ? strdup((const char *)pdu->value) :
NULL;
flist_add_tail(&p->list, opt_list);
p->value = pdu->value[0] ? strdup((const char *)pdu->value) :
NULL;
flist_add_tail(&p->list, opt_list);
- } else {
- free(p->name);
- free(p);