Skip to content

Memory leak while using firewall.go #39

@pepperoni01

Description

@pepperoni01

Hey @iamacarpet.

I'm trying to use a part of a package to control windows firewall.

It works well, but it doesn't release memory. For example, running functions in a loop will cause continuous incremental memory usage.

Looking at the library, it seems that this topic is taken care of(functions like firewallAPIRelease, firewallRulesEnumRealease).

Here's an example of code that replicates an issue.

package main

import (
    "fmt"
    winapi "github.com/kumako/go-win64api"
    "time"
)

func main(){
    var first string
    for 1>0 {
        fmt.Scanln(&first)
        if first == "run"{
            firewallTest()
        }
    }
}

func firewallTest(){
    //get the list of the rules
    ruleList, _ := winapi.FirewallRulesGet()
    //delete them one by one using their names
    for _, eachRule := range ruleList {
        ruleName := eachRule.Name
        if ruleName != ""{
            winapi.FirewallRuleDelete(ruleName)
        }
    }
    //wait for 30 second
    time.Sleep(30 * time.Second)
    //add them back, one by one, from the list
    for _, eachRule := range ruleList{
        winapi.FirewallRuleAddAdvanced(eachRule)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions