compare pointer against NULL, not 0
diff --git a/lib/repository.c b/lib/repository.c
index 3e583b2..34d0da4 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -685,7 +685,7 @@ got_repo_search_packidx(struct got_packidx **packidx, int *idx,
err = got_error_no_obj(id);
done:
free(path_packdir);
- if (packdir && closedir(packdir) != 0 && err == 0)
+ if (packdir && closedir(packdir) != 0 && err == NULL)
err = got_error_from_errno("closedir");
return err;
}