nvme/overhead: fix a memory leak issue
Fix issue #393. The memory is not completely released, there are mutiple malloc list, but only the last one is released. So I free all. Change-Id: I14a583871811b54017728b6a7e92982cd75bd6b1 Signed-off-by: WangHaiLiang <hailiangx.e.wang@intel.com> Reviewed-on: https://review.gerrithub.io/422682 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
b07d3bd2bd
commit
4df8ba86f2
@ -79,6 +79,7 @@ struct ns_entry {
|
|||||||
bool is_draining;
|
bool is_draining;
|
||||||
uint32_t current_queue_depth;
|
uint32_t current_queue_depth;
|
||||||
char name[1024];
|
char name[1024];
|
||||||
|
struct ns_entry *next;
|
||||||
|
|
||||||
struct spdk_histogram_data *submit_histogram;
|
struct spdk_histogram_data *submit_histogram;
|
||||||
struct spdk_histogram_data *complete_histogram;
|
struct spdk_histogram_data *complete_histogram;
|
||||||
@ -155,6 +156,7 @@ register_ns(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ns *ns)
|
|||||||
|
|
||||||
snprintf(entry->name, 44, "%-20.20s (%-20.20s)", cdata->mn, cdata->sn);
|
snprintf(entry->name, 44, "%-20.20s (%-20.20s)", cdata->mn, cdata->sn);
|
||||||
|
|
||||||
|
entry->next = g_ns;
|
||||||
g_ns = entry;
|
g_ns = entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,6 +175,8 @@ register_ctrlr(struct spdk_nvme_ctrlr *ctrlr)
|
|||||||
snprintf(entry->name, sizeof(entry->name), "%-20.20s (%-20.20s)", cdata->mn, cdata->sn);
|
snprintf(entry->name, sizeof(entry->name), "%-20.20s (%-20.20s)", cdata->mn, cdata->sn);
|
||||||
|
|
||||||
entry->ctrlr = ctrlr;
|
entry->ctrlr = ctrlr;
|
||||||
|
|
||||||
|
entry->next = g_ctrlr;
|
||||||
g_ctrlr = entry;
|
g_ctrlr = entry;
|
||||||
|
|
||||||
num_ns = spdk_nvme_ctrlr_get_num_ns(ctrlr);
|
num_ns = spdk_nvme_ctrlr_get_num_ns(ctrlr);
|
||||||
@ -627,6 +631,30 @@ register_controllers(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cleanup(void)
|
||||||
|
{
|
||||||
|
struct ns_entry *ns_entry = g_ns;
|
||||||
|
struct ctrlr_entry *ctrlr_entry = g_ctrlr;
|
||||||
|
|
||||||
|
while (ns_entry) {
|
||||||
|
struct ns_entry *next = ns_entry->next;
|
||||||
|
|
||||||
|
spdk_histogram_data_free(ns_entry->submit_histogram);
|
||||||
|
spdk_histogram_data_free(ns_entry->complete_histogram);
|
||||||
|
free(ns_entry);
|
||||||
|
ns_entry = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (ctrlr_entry) {
|
||||||
|
struct ctrlr_entry *next = ctrlr_entry->next;
|
||||||
|
|
||||||
|
spdk_nvme_detach(ctrlr_entry->ctrlr);
|
||||||
|
free(ctrlr_entry);
|
||||||
|
ctrlr_entry = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
@ -664,15 +692,15 @@ int main(int argc, char **argv)
|
|||||||
if (g_aio_optind < argc) {
|
if (g_aio_optind < argc) {
|
||||||
printf("Measuring overhead for AIO device %s.\n", argv[g_aio_optind]);
|
printf("Measuring overhead for AIO device %s.\n", argv[g_aio_optind]);
|
||||||
if (register_aio_file(argv[g_aio_optind]) != 0) {
|
if (register_aio_file(argv[g_aio_optind]) != 0) {
|
||||||
rc = -1;
|
cleanup();
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (register_controllers() != 0) {
|
if (register_controllers() != 0) {
|
||||||
rc = -1;
|
cleanup();
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -682,16 +710,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
print_stats();
|
print_stats();
|
||||||
|
|
||||||
cleanup:
|
cleanup();
|
||||||
if (g_ns) {
|
|
||||||
spdk_histogram_data_free(g_ns->submit_histogram);
|
|
||||||
spdk_histogram_data_free(g_ns->complete_histogram);
|
|
||||||
free(g_ns);
|
|
||||||
}
|
|
||||||
if (g_ctrlr) {
|
|
||||||
spdk_nvme_detach(g_ctrlr->ctrlr);
|
|
||||||
free(g_ctrlr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
fprintf(stderr, "%s: errors occured\n", argv[0]);
|
fprintf(stderr, "%s: errors occured\n", argv[0]);
|
||||||
|
Loading…
Reference in New Issue
Block a user