diff --git a/include/lsof.h b/include/lsof.h index 277e1af7..30ee16e6 100644 --- a/include/lsof.h +++ b/include/lsof.h @@ -572,6 +572,8 @@ enum lsof_error lsof_gather(struct lsof_context *ctx, * You should call `lsof_free_result` to free all `struct lsof_result` * before destroying the context. * + * ctx may be NULL. + * * You must not use the context anymore after this call. * * \since API version 1 @@ -579,6 +581,8 @@ enum lsof_error lsof_gather(struct lsof_context *ctx, void lsof_destroy(struct lsof_context *ctx); /** Free struct lsof_result + * + * result may be NULL. * * \since API version 1 */ diff --git a/lib/lsof.c b/lib/lsof.c index af4b04fd..cc60c7c4 100644 --- a/lib/lsof.c +++ b/lib/lsof.c @@ -732,6 +732,9 @@ void lsof_free_result(struct lsof_result *result) { int pi, fi; struct lsof_process *p; struct lsof_file *f; + if (!result) { + return; + } for (pi = 0; pi < result->num_processes; pi++) { p = &result->processes[pi]; /* Free files */