Skip to content
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

cmd/gnoland: execBalancesExport leaks the opened file and at no point closes it #3032

Closed
odeke-em opened this issue Oct 27, 2024 · 2 comments · Fixed by #3294
Closed

cmd/gnoland: execBalancesExport leaks the opened file and at no point closes it #3032

odeke-em opened this issue Oct 27, 2024 · 2 comments · Fixed by #3294
Assignees
Labels
security Security-sensitive issue

Comments

@odeke-em
Copy link
Contributor

Reading through this code

func execBalancesExport(cfg *balancesCfg, io commands.IO, args []string) error {
// Load the genesis
genesis, loadErr := types.GenesisDocFromFile(cfg.genesisPath)
if loadErr != nil {
return fmt.Errorf("unable to load genesis, %w", loadErr)
}
// Load the genesis state
if genesis.AppState == nil {
return errAppStateNotSet
}
state := genesis.AppState.(gnoland.GnoGenesisState)
if len(state.Balances) == 0 {
io.Println("No genesis balances to export")
return nil
}
// Make sure the output file path is specified
if len(args) == 0 {
return errNoOutputFile
}
// Open output file
outputFile, err := os.OpenFile(
args[0],
os.O_RDWR|os.O_CREATE|os.O_APPEND,
0o755,
)
if err != nil {
return fmt.Errorf("unable to create output file, %w", err)
}
// Save the balances
for _, balance := range state.Balances {
if _, err = outputFile.WriteString(
fmt.Sprintf("%s\n", balance),
); err != nil {
return fmt.Errorf("unable to write to output, %w", err)
}
}
io.Printfln(
"Exported %d balances",
len(state.Balances),
)
return nil
}

at no point is the file that's opened per

outputFile, err := os.OpenFile(

ever closed

@kristovatlas
Copy link
Contributor

Thanks for the report, @odeke-em. We're looking into it.

odeke-em added a commit to odeke-em/gno that referenced this issue Dec 7, 2024
Ensures that the opened file is not leaked and
closed after use.

Fixes gnolang#3032
@odeke-em
Copy link
Contributor Author

odeke-em commented Dec 7, 2024

I've mailed out PR #3294.

thehowl pushed a commit that referenced this issue Dec 7, 2024
Ensures that the opened file is not leaked and
closed after use.

Fixes #3032
omarsy pushed a commit to TERITORI/gno that referenced this issue Dec 7, 2024
Ensures that the opened file is not leaked and
closed after use.

Fixes gnolang#3032
Villaquiranm pushed a commit to Villaquiranm/gno that referenced this issue Dec 9, 2024
Ensures that the opened file is not leaked and
closed after use.

Fixes gnolang#3032
r3v4s pushed a commit to gnoswap-labs/gno that referenced this issue Dec 10, 2024
Ensures that the opened file is not leaked and
closed after use.

Fixes gnolang#3032
albttx pushed a commit that referenced this issue Jan 10, 2025
Ensures that the opened file is not leaked and
closed after use.

Fixes #3032
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
security Security-sensitive issue
Projects
Development

Successfully merging a pull request may close this issue.

2 participants