Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
The Tor Project
Core
Tor
Commits
c7951731
Commit
c7951731
authored
10 years ago
by
Nick Mathewson
Browse files
Options
Downloads
Patches
Plain Diff
Fix memory leaks in test_circuit_timeout
Found with valgrind.
parent
d2147cc7
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/or/statefile.c
+22
-7
22 additions, 7 deletions
src/or/statefile.c
src/or/statefile.h
+2
-0
2 additions, 0 deletions
src/or/statefile.h
src/test/test.c
+11
-5
11 additions, 5 deletions
src/test/test.c
with
35 additions
and
12 deletions
src/or/statefile.c
+
22
−
7
View file @
c7951731
...
...
@@ -294,6 +294,16 @@ or_state_save_broken(char *fname)
tor_free
(
fname2
);
}
STATIC
or_state_t
*
or_state_new
(
void
)
{
or_state_t
*
new_state
=
tor_malloc_zero
(
sizeof
(
or_state_t
));
new_state
->
magic_
=
OR_STATE_MAGIC
;
config_init
(
&
state_format
,
new_state
);
return
new_state
;
}
/** Reload the persistent state from disk, generating a new state as needed.
* Return 0 on success, less than 0 on failure.
*/
...
...
@@ -321,9 +331,7 @@ or_state_load(void)
log_warn
(
LD_GENERAL
,
"State file
\"
%s
\"
is not a file? Failing."
,
fname
);
goto
done
;
}
new_state
=
tor_malloc_zero
(
sizeof
(
or_state_t
));
new_state
->
magic_
=
OR_STATE_MAGIC
;
config_init
(
&
state_format
,
new_state
);
new_state
=
or_state_new
();
if
(
contents
)
{
config_line_t
*
lines
=
NULL
;
int
assign_retval
;
...
...
@@ -358,9 +366,7 @@ or_state_load(void)
tor_free
(
contents
);
config_free
(
&
state_format
,
new_state
);
new_state
=
tor_malloc_zero
(
sizeof
(
or_state_t
));
new_state
->
magic_
=
OR_STATE_MAGIC
;
config_init
(
&
state_format
,
new_state
);
new_state
=
or_state_new
();
}
else
if
(
contents
)
{
log_info
(
LD_GENERAL
,
"Loaded state from
\"
%s
\"
"
,
fname
);
}
else
{
...
...
@@ -625,10 +631,19 @@ save_transport_to_state(const char *transport,
tor_free
(
transport_addrport
);
}
STATIC
void
or_state_free
(
or_state_t
*
state
)
{
if
(
!
state
)
return
;
config_free
(
&
state_format
,
state
);
}
void
or_state_free_all
(
void
)
{
config_free
(
&
state_format
,
global_state
);
or_state_free
(
global_state
);
global_state
=
NULL
;
}
This diff is collapsed.
Click to expand it.
src/or/statefile.h
+
2
−
0
View file @
c7951731
...
...
@@ -20,6 +20,8 @@ void or_state_free_all(void);
#ifdef STATEFILE_PRIVATE
STATIC
config_line_t
*
get_transport_in_state_by_name
(
const
char
*
transport
);
STATIC
void
or_state_free
(
or_state_t
*
state
);
STATIC
or_state_t
*
or_state_new
(
void
);
#endif
#endif
...
...
This diff is collapsed.
Click to expand it.
src/test/test.c
+
11
−
5
View file @
c7951731
...
...
@@ -32,6 +32,7 @@ const char tor_git_revision[] = "";
#define ROUTER_PRIVATE
#define CIRCUITSTATS_PRIVATE
#define CIRCUITLIST_PRIVATE
#define STATEFILE_PRIVATE
/*
* Linux doesn't provide lround in math.h by default, but mac os does...
...
...
@@ -59,6 +60,7 @@ double fabs(double x);
#include
"policies.h"
#include
"rephist.h"
#include
"routerparse.h"
#include
"statefile.h"
#ifdef CURVE25519_ENABLED
#include
"crypto_curve25519.h"
#include
"onion_ntor.h"
...
...
@@ -466,14 +468,14 @@ test_circuit_timeout(void)
circuit_build_times_t
estimate
;
circuit_build_times_t
final
;
double
timeout1
,
timeout2
;
or_state_t
state
;
or_state_t
*
state
=
NULL
;
int
i
,
runs
;
double
close_ms
;
circuit_build_times_init
(
&
initial
);
circuit_build_times_init
(
&
estimate
);
circuit_build_times_init
(
&
final
);
memset
(
&
state
,
0
,
sizeof
(
or_state_
t
)
);
state
=
or_state_
new
(
);
circuitbuild_running_unit_tests
();
#define timeout0 (build_time_t)(30*1000.0)
...
...
@@ -505,8 +507,9 @@ test_circuit_timeout(void)
test_assert
(
estimate
.
total_build_times
<=
CBT_NCIRCUITS_TO_OBSERVE
);
circuit_build_times_update_state
(
&
estimate
,
&
state
);
test_assert
(
circuit_build_times_parse_state
(
&
final
,
&
state
)
==
0
);
circuit_build_times_update_state
(
&
estimate
,
state
);
circuit_build_times_free_timeouts
(
&
final
);
test_assert
(
circuit_build_times_parse_state
(
&
final
,
state
)
==
0
);
circuit_build_times_update_alpha
(
&
final
);
timeout2
=
circuit_build_times_calculate_timeout
(
&
final
,
...
...
@@ -595,7 +598,10 @@ test_circuit_timeout(void)
}
done:
return
;
circuit_build_times_free_timeouts
(
&
initial
);
circuit_build_times_free_timeouts
(
&
estimate
);
circuit_build_times_free_timeouts
(
&
final
);
or_state_free
(
state
);
}
/** Test encoding and parsing of rendezvous service descriptors. */
...
...
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