-
Notifications
You must be signed in to change notification settings - Fork 13
Fix logging segfault by leaking logger #470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -145,7 +145,7 @@ TEST_F(nix_api_util_context, nix_set_logger_routes_log_calls) | |||||||||
| LogCapture capture; | ||||||||||
| // Restore the default logger before `capture` goes out of scope so | ||||||||||
| // the destroy callback runs while `capture` is still alive. | ||||||||||
| Finally restoreLogger([] { nix::logger = nix::makeSimpleLogger(); }); | ||||||||||
| Finally restoreLogger([] { nix::logger = nix::makeSimpleLogger().release(); }); | ||||||||||
|
|
||||||||||
| ASSERT_EQ(nix_set_logger(ctx, &captureLoggerVtable, &capture), NIX_OK); | ||||||||||
|
|
||||||||||
|
|
@@ -163,7 +163,7 @@ TEST_F(nix_api_util_context, nix_set_logger_routes_log_calls) | |||||||||
| TEST_F(nix_api_util_context, nix_set_logger_routes_activities_and_results) | ||||||||||
| { | ||||||||||
| LogCapture capture; | ||||||||||
| Finally restoreLogger([] { nix::logger = nix::makeSimpleLogger(); }); | ||||||||||
| Finally restoreLogger([] { nix::logger = nix::makeSimpleLogger().release(); }); | ||||||||||
|
|
||||||||||
| ASSERT_EQ(nix_set_logger(ctx, &captureLoggerVtable, &capture), NIX_OK); | ||||||||||
|
|
||||||||||
|
|
@@ -191,20 +191,20 @@ TEST_F(nix_api_util_context, nix_set_logger_routes_activities_and_results) | |||||||||
| EXPECT_EQ(capture.stops[0], actId); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| TEST_F(nix_api_util_context, nix_set_logger_invokes_destroy_when_replaced) | ||||||||||
| TEST_F(nix_api_util_context, nix_set_logger_does_not_invoke_destroy_when_replaced) | ||||||||||
| { | ||||||||||
| // Both captures must outlive the Finally so that the logger held | ||||||||||
| // by `nix::logger` at teardown can call destroy on a live capture. | ||||||||||
|
Comment on lines
196
to
197
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment contradicts test behavior regarding destroy lifecycle. The comment states that "the logger held by
Consider clarifying whether destroy is expected to be called at any point in the test lifecycle, or remove the reference to destroy being called. 📝 Suggested clarification- // Both captures must outlive the Finally so that the logger held
- // by `nix::logger` at teardown can call destroy on a live capture.
+ // Both captures must outlive the Finally block.
+ // Note: destroy is not called when replacing loggers.📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| LogCapture capture; | ||||||||||
| LogCapture capture2; | ||||||||||
| Finally restoreLogger([] { nix::logger = nix::makeSimpleLogger(); }); | ||||||||||
| Finally restoreLogger([] { nix::logger = nix::makeSimpleLogger().release(); }); | ||||||||||
|
|
||||||||||
| ASSERT_EQ(nix_set_logger(ctx, &captureLoggerVtable, &capture), NIX_OK); | ||||||||||
| EXPECT_FALSE(capture.destroyed); | ||||||||||
|
|
||||||||||
| // Replacing the logger must fire destroy on the old userdata. | ||||||||||
| // Replacing the logger won't destroy the old logger. | ||||||||||
| ASSERT_EQ(nix_set_logger(ctx, &captureLoggerVtable, &capture2), NIX_OK); | ||||||||||
| EXPECT_TRUE(capture.destroyed); | ||||||||||
| EXPECT_FALSE(capture.destroyed); | ||||||||||
| EXPECT_FALSE(capture2.destroyed); | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.