OpenDataPlane / odp

The ODP project is an open-source, cross-platform set of application programming interfaces (APIs) for the networking data plane

Home Page:https://opendataplane.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing closing files

ryancaicse opened this issue · comments

return -1; should be goto quit;? Otherwise, the file test_global.file = fopen(test_global.filename, "w"); is not closed.

/* Init ODP before calling anything else */
if (odp_init_global(&instance, init_ptr, NULL)) {
printf("Global init failed.\n");
return -1;
}
/* Init this thread */
if (odp_init_local(instance, ODP_THREAD_WORKER)) {
printf("Local init failed.\n");
return -1;
}

if (test_global.opt.output) {
test_global.file = fopen(test_global.filename, "w");
if (test_global.file == NULL) {
printf("Failed to open file: %s\n",
test_global.filename);
return -1;
}
}

quit:
if (test_global.file)
fclose(test_global.file);
if (test_global.timer_ctx && destroy_timers(&test_global))
ret = -1;
if (test_global.timer_ctx)
free(test_global.timer_ctx);
if (test_global.log)
odp_shm_free(test_global.log_shm);
if (odp_term_local()) {
printf("Term local failed.\n");
ret = -1;
}
if (odp_term_global(instance)) {
printf("Term global failed.\n");
ret = -1;
}
return ret;

Thanks for the report. PR #1461 fixes this issue.