feat: sync codex oauth into opencode auth/runtime#47
Open
jyuny1 wants to merge 1 commit intoLoongphy:mainfrom
Open
feat: sync codex oauth into opencode auth/runtime#47jyuny1 wants to merge 1 commit intoLoongphy:mainfrom
jyuny1 wants to merge 1 commit intoLoongphy:mainfrom
Conversation
Comment on lines
+348
to
+358
| fn resolveOpencodeConfigDir(allocator: std.mem.Allocator, user_home: []const u8) ![]u8 { | ||
| if (@import("builtin").os.tag == .windows) { | ||
| if (try getNonEmptyEnvVarOwned(allocator, "APPDATA")) |app_data| return std.fs.path.join(allocator, &[_][]const u8{ app_data, "opencode" }); | ||
| return std.fs.path.join(allocator, &[_][]const u8{ user_home, "AppData", "Roaming", "opencode" }); | ||
| } | ||
|
|
||
| if (try getNonEmptyEnvVarOwned(allocator, "XDG_CONFIG_HOME")) |xdg| { | ||
| return std.fs.path.join(allocator, &[_][]const u8{ xdg, "opencode" }); | ||
| } | ||
| return std.fs.path.join(allocator, &[_][]const u8{ user_home, ".config", "opencode" }); | ||
| } |
There was a problem hiding this comment.
🟡 Medium src/opencode_sync.zig:348
resolveOpencodeConfigDir and resolveOpencodeDataDir leak memory when getNonEmptyEnvVarOwned returns a non-null value. On Windows with APPDATA set, or on Unix with XDG_CONFIG_HOME/XDG_DATA_HOME set, the returned app_data or xdg string is never freed before the function returns. Each call to sync() leaks the environment variable's value. Add defer allocator.free(...) before returning the joined path.
fn resolveOpencodeConfigDir(allocator: std.mem.Allocator, user_home: []const u8) ![]u8 {
if (@import("builtin").os.tag == .windows) {
- if (try getNonEmptyEnvVarOwned(allocator, "APPDATA")) |app_data| return std.fs.path.join(allocator, &[_][]const u8{ app_data, "opencode" });
+ if (try getNonEmptyEnvVarOwned(allocator, "APPDATA")) |app_data| {
+ defer allocator.free(app_data);
+ return std.fs.path.join(allocator, &[_][]const u8{ app_data, "opencode" });
+ }
return std.fs.path.join(allocator, &[_][]const u8{ user_home, "AppData", "Roaming", "opencode" });
}
- if (try getNonEmptyEnvVarOwned(allocator, "XDG_CONFIG_HOME")) |xdg| {
+ if (try getNonEmptyEnvVarOwned(allocator, "XDG_CONFIG_HOME")) |xdg| {
+ defer allocator.free(xdg);
return std.fs.path.join(allocator, &[_][]const u8{ xdg, "opencode" });
}
return std.fs.path.join(allocator, &[_][]const u8{ user_home, ".config", "opencode" });🤖 Copy this AI Prompt to have your agent fix this:
In file src/opencode_sync.zig around lines 348-358:
`resolveOpencodeConfigDir` and `resolveOpencodeDataDir` leak memory when `getNonEmptyEnvVarOwned` returns a non-null value. On Windows with `APPDATA` set, or on Unix with `XDG_CONFIG_HOME`/`XDG_DATA_HOME` set, the returned `app_data` or `xdg` string is never freed before the function returns. Each call to `sync()` leaks the environment variable's value. Add `defer allocator.free(...)` before returning the joined path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Why
Behavior
Validation
Note
Sync Codex OAuth credentials into opencode auth files and running servers
codex-accounts.jsonandauth.jsoninto the opencode config/data directories derived from the Codex registry and active auth snapshot.login,import_auth,remove_account), running opencode servers are discovered vialsofand their auth state is updated via HTTP PUT/DELETE to/auth/openai.auth.jsonfiles are preserved during sync.switchcommand now prints a standardized success message including email, alias, and account name.discoverRunningServersshells out tolsofand is a no-op on Windows; sync/refresh failures are downgraded to warnings so they never abort the main command.📊 Macroscope summarized bc147dc. 3 files reviewed, 1 issue evaluated, 0 issues filtered, 1 comment posted
🗂️ Filtered Issues