Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
go-systemd
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
le
go-systemd
Commits
4d9b60f9
Commit
4d9b60f9
authored
9 years ago
by
Iago López Galeiras
Browse files
Options
Downloads
Patches
Plain Diff
sdjournal: close dlopen handle on error in New* functions
We don't want to leak it.
parent
c14ce9e6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sdjournal/journal.go
+22
-4
22 additions, 4 deletions
sdjournal/journal.go
with
22 additions
and
4 deletions
sdjournal/journal.go
+
22
−
4
View file @
4d9b60f9
...
...
@@ -278,13 +278,22 @@ func (j *Journal) getFunction(name string) (unsafe.Pointer, error) {
}
// NewJournal returns a new Journal instance pointing to the local journal
func
NewJournal
()
(
*
Journal
,
error
)
{
func
NewJournal
()
(
j
*
Journal
,
err
error
)
{
h
,
err
:=
dlopen
.
GetHandle
(
libsystemdNames
)
if
err
!=
nil
{
return
nil
,
err
}
defer
func
()
{
if
err
==
nil
{
return
}
err2
:=
h
.
Close
()
if
err2
!=
nil
{
err
=
fmt
.
Errorf
(
`%q and "error closing handle: %v"`
,
err
,
err2
)
}
}()
j
:
=
&
Journal
{
lib
:
h
}
j
=
&
Journal
{
lib
:
h
}
sd_journal_open
,
err
:=
j
.
getFunction
(
"sd_journal_open"
)
if
err
!=
nil
{
...
...
@@ -303,18 +312,27 @@ func NewJournal() (*Journal, error) {
// NewJournalFromDir returns a new Journal instance pointing to a journal residing
// in a given directory. The supplied path may be relative or absolute; if
// relative, it will be converted to an absolute path before being opened.
func
NewJournalFromDir
(
path
string
)
(
*
Journal
,
error
)
{
func
NewJournalFromDir
(
path
string
)
(
j
*
Journal
,
err
error
)
{
h
,
err
:=
dlopen
.
GetHandle
(
libsystemdNames
)
if
err
!=
nil
{
return
nil
,
err
}
defer
func
()
{
if
err
==
nil
{
return
}
err2
:=
h
.
Close
()
if
err2
!=
nil
{
err
=
fmt
.
Errorf
(
`%q and "error closing handle: %v"`
,
err
,
err2
)
}
}()
path
,
err
=
filepath
.
Abs
(
path
)
if
err
!=
nil
{
return
nil
,
err
}
j
:
=
&
Journal
{
lib
:
h
}
j
=
&
Journal
{
lib
:
h
}
sd_journal_open_directory
,
err
:=
j
.
getFunction
(
"sd_journal_open_directory"
)
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment