Skip to content

Commit d187b21

Browse files
committed
fabrics: Duplicate strings when merging configs
We have to use strdup here, because the merged config will be freeing these pointers eventually. Without it, we are going to double free it. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 1dd2e76 commit d187b21

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/nvme/fabrics.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,15 @@ void nvmf_default_config(struct nvme_fabrics_config *cfg)
191191

192192
#define MERGE_CFG_OPTION(c, n, o, d) \
193193
if ((c)->o == d) (c)->o = (n)->o
194+
#define MERGE_CFG_OPTION_STR(c, n, o, d) \
195+
if ((c)->o == d && (n)->o) (c)->o = strdup((n)->o)
194196
static struct nvme_fabrics_config *merge_config(nvme_ctrl_t c,
195197
const struct nvme_fabrics_config *cfg)
196198
{
197199
struct nvme_fabrics_config *ctrl_cfg = nvme_ctrl_get_config(c);
198200

199-
MERGE_CFG_OPTION(ctrl_cfg, cfg, host_traddr, NULL);
200-
MERGE_CFG_OPTION(ctrl_cfg, cfg, host_iface, NULL);
201+
MERGE_CFG_OPTION_STR(ctrl_cfg, cfg, host_traddr, NULL);
202+
MERGE_CFG_OPTION_STR(ctrl_cfg, cfg, host_iface, NULL);
201203
MERGE_CFG_OPTION(ctrl_cfg, cfg, nr_io_queues, 0);
202204
MERGE_CFG_OPTION(ctrl_cfg, cfg, nr_write_queues, 0);
203205
MERGE_CFG_OPTION(ctrl_cfg, cfg, nr_poll_queues, 0);

0 commit comments

Comments
 (0)