Skip to content

Commit 4713290

Browse files
authored
Merge pull request #349 from neek78/small_changes
lsof_free_result(): handle result == NULL
2 parents 00b7bae + 34ea683 commit 4713290

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

include/lsof.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,13 +572,17 @@ enum lsof_error lsof_gather(struct lsof_context *ctx,
572572
* You should call `lsof_free_result` to free all `struct lsof_result`
573573
* before destroying the context.
574574
*
575+
* ctx may be NULL.
576+
*
575577
* You must not use the context anymore after this call.
576578
*
577579
* \since API version 1
578580
*/
579581
void lsof_destroy(struct lsof_context *ctx);
580582

581583
/** Free struct lsof_result
584+
*
585+
* result may be NULL.
582586
*
583587
* \since API version 1
584588
*/

lib/lsof.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,9 @@ void lsof_free_result(struct lsof_result *result) {
732732
int pi, fi;
733733
struct lsof_process *p;
734734
struct lsof_file *f;
735+
if (!result) {
736+
return;
737+
}
735738
for (pi = 0; pi < result->num_processes; pi++) {
736739
p = &result->processes[pi];
737740
/* Free files */

0 commit comments

Comments
 (0)