ut/scsi/dev: fix memory leak in lun_construct stub
Check if a LUN already exists before allocating the spdk_scsi_lun
structure - this matches the real implementation of
spdk_scsi_lun_construct().
Fixes: e44731d659
("scsi: Remove the claimed flag from LUN")
Change-Id: I529648f93cd21e9f19ce82ef571cabe9c7e8c49a
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/390903
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
parent
deddb8d831
commit
a7d816bfbe
@ -97,18 +97,18 @@ spdk_scsi_lun_construct(const char *name, struct spdk_bdev *bdev,
|
|||||||
struct spdk_scsi_lun *lun;
|
struct spdk_scsi_lun *lun;
|
||||||
struct lun_entry *p;
|
struct lun_entry *p;
|
||||||
|
|
||||||
lun = calloc(1, sizeof(struct spdk_scsi_lun));
|
|
||||||
SPDK_CU_ASSERT_FATAL(lun != NULL);
|
|
||||||
|
|
||||||
snprintf(lun->name, sizeof(lun->name), "%s", name);
|
|
||||||
lun->bdev = bdev;
|
|
||||||
|
|
||||||
TAILQ_FOREACH(p, &g_lun_head, lun_entries) {
|
TAILQ_FOREACH(p, &g_lun_head, lun_entries) {
|
||||||
CU_ASSERT_FATAL(p->lun != NULL);
|
CU_ASSERT_FATAL(p->lun != NULL);
|
||||||
if (strncmp(p->lun->name, lun->name, sizeof(lun->name)) == 0)
|
if (strcmp(p->lun->name, name) == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lun = calloc(1, sizeof(struct spdk_scsi_lun));
|
||||||
|
SPDK_CU_ASSERT_FATAL(lun != NULL);
|
||||||
|
snprintf(lun->name, sizeof(lun->name), "%s", name);
|
||||||
|
lun->bdev = bdev;
|
||||||
|
|
||||||
p = calloc(1, sizeof(struct lun_entry));
|
p = calloc(1, sizeof(struct lun_entry));
|
||||||
SPDK_CU_ASSERT_FATAL(p != NULL);
|
SPDK_CU_ASSERT_FATAL(p != NULL);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user