Break core structs down into obj and leak packages

This commit is contained in:
2018-07-08 02:56:51 +01:00
parent 2fdb51166c
commit 6883984950
5 changed files with 21 additions and 16 deletions

View File

@@ -1,24 +1,28 @@
package main
package leak
import "fmt"
import (
"fmt"
func NewLeakFinder(file1, file2, file3 string) *LeakFinder {
return &LeakFinder{
"github.com/jimeh/rbheapleak/obj"
)
func NewFinder(file1, file2, file3 string) *Finder {
return &Finder{
FilePaths: [3]string{file1, file2, file3},
}
}
type LeakFinder struct {
type Finder struct {
FilePaths [3]string
Dumps [3]*Dump
Dumps [3]*obj.Dump
Leaks []*string
Verbose bool
}
func (s *LeakFinder) Process() error {
func (s *Finder) Process() error {
for i, filePath := range s.FilePaths {
s.log(fmt.Sprintf("Parsing %s", filePath))
dump := NewDump(filePath)
dump := obj.NewDump(filePath)
err := dump.Process()
if err != nil {
@@ -32,17 +36,17 @@ func (s *LeakFinder) Process() error {
return nil
}
func (s *LeakFinder) PrintLeakedAddresses() {
func (s *Finder) PrintLeakedAddresses() {
s.log("\nLeaked Addresses:")
s.Dumps[1].PrintEntryAddress(s.FindLeaks())
}
func (s *LeakFinder) PrintLeakedObjects() {
func (s *Finder) PrintLeakedObjects() {
s.log("\nLeaked Objects:")
s.Dumps[1].PrintEntryJSON(s.FindLeaks())
}
func (s *LeakFinder) FindLeaks() []*string {
func (s *Finder) FindLeaks() []*string {
if s.Leaks != nil {
return s.Leaks
}
@@ -70,7 +74,7 @@ func (s *LeakFinder) FindLeaks() []*string {
return s.Leaks
}
func (s *LeakFinder) log(msg string) {
func (s *Finder) log(msg string) {
if s.Verbose {
fmt.Println(msg)
}

View File

@@ -1,4 +1,4 @@
package main
package obj
import (
"bufio"

View File

@@ -1,4 +1,4 @@
package main
package obj
func NewEntry(inputJSON []byte) (*Entry, error) {
obj, err := NewObject(inputJSON)

View File

@@ -1,4 +1,4 @@
package main
package obj
import "encoding/json"

View File

@@ -1,9 +1,10 @@
// Code generated by easyjson for marshaling/unmarshaling. DO NOT EDIT.
package main
package obj
import (
json "encoding/json"
easyjson "github.com/mailru/easyjson"
jlexer "github.com/mailru/easyjson/jlexer"
jwriter "github.com/mailru/easyjson/jwriter"