Merge lp:~thisfred/u1db/fix-my-faucet into lp:u1db

Proposed by Eric Casteleijn
Status: Merged
Approved by: Sidnei da Silva
Approved revision: 303
Merged at revision: 305
Proposed branch: lp:~thisfred/u1db/fix-my-faucet
Merge into: lp:u1db
Diff against target: 61 lines (+12/-7)
2 files modified
src/u1db_sync_target.c (+6/-4)
u1db/tests/c_backend_wrapper.pyx (+6/-3)
To merge this branch: bzr merge lp:~thisfred/u1db/fix-my-faucet
Reviewer Review Type Date Requested Status
John A Meinel (community) Approve
Lucio Torre (community) Approve
Review via email: mp+106685@code.launchpad.net

Commit message

Fixed two memory leaks.

Description of the change

Fixed two memory leaks.

To post a comment you must log in.
Revision history for this message
Lucio Torre (lucio.torre) :
review: Approve
Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 5/21/2012 8:31 PM, Eric Casteleijn wrote:
> Eric Casteleijn has proposed merging
> lp:~thisfred/u1db/fix-my-faucet into lp:u1db.
>
> Requested reviews: Ubuntu One hackers (ubuntuone-hackers)
>
> For more details, see:
> https://code.launchpad.net/~thisfred/u1db/fix-my-faucet/+merge/106685
>
> Fixed two memory leaks.

- - handle_status("create_index",
- - u1db_create_index(self._db, index_name, n_expressions,
expressions))
- - free(<void*>expressions)
+ try:
+ handle_status("create_index",
+ u1db_create_index(
+ self._db, index_name, n_expressions, expressions))
+ finally:
+ free(<void*>expressions)

This might be easier to read as:

status = u1db_create_index(...)
free(<void*>expressions)
handle_status(...)

Though the try/finally form seems fine, too.

 review: approve
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk+7XKkACgkQJdeBCYSNAAOZ6ACbBQDTOSzqB4ztc65rxg0zWR3E
sFIAn09n56/yWYWhDTgJkmywwmMJRSw9
=MdU2
-----END PGP SIGNATURE-----

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/u1db_sync_target.c'
2--- src/u1db_sync_target.c 2012-05-18 15:12:42 +0000
3+++ src/u1db_sync_target.c 2012-05-21 18:33:19 +0000
4@@ -282,7 +282,8 @@
5 status = u1db__put_doc_if_newer(se->db, doc, 0, se->source_replica_uid,
6 source_gen, NULL, &insert_state, &at_gen);
7 if (insert_state == U1DB_INSERTED || insert_state == U1DB_CONVERGED) {
8- lh_table_insert(se->seen_ids, strdup(doc->doc_id), (void *)(intptr_t)at_gen);
9+ lh_table_insert(se->seen_ids, strdup(doc->doc_id),
10+ (void *)(intptr_t)at_gen);
11 } else {
12 // state should be either U1DB_SUPERSEDED or U1DB_CONFLICTED, in either
13 // case, we don't count this as a 'seen_id' because we will want to be
14@@ -311,7 +312,7 @@
15 struct _whats_changed_doc_ids_state *state;
16 state = (struct _whats_changed_doc_ids_state *)context;
17 if (state->exclude_ids != NULL
18- && (e = lh_table_lookup_entry(state->exclude_ids, doc_id)) != NULL
19+ && (e = lh_table_lookup_entry(state->exclude_ids, doc_id)) != NULL
20 && (intptr_t)e->v >= gen)
21 {
22 // This document was already seen at this gen,
23@@ -560,7 +561,8 @@
24 // fprintf(stderr, "Starting\n");
25 if (db == NULL || target == NULL || local_gen_before_sync == NULL) {
26 // fprintf(stderr, "DB, target, or local are NULL\n");
27- return U1DB_INVALID_PARAMETER;
28+ status = U1DB_INVALID_PARAMETER;
29+ goto finish;
30 }
31
32 status = u1db_get_replica_uid(db, &local_uid);
33@@ -583,7 +585,7 @@
34 if (local_gen == local_gen_known_by_target
35 && target_gen == target_gen_known_by_local)
36 {
37- return U1DB_OK;
38+ goto finish;
39 }
40 *local_gen_before_sync = local_gen;
41 return_doc_state.db = db;
42
43=== modified file 'u1db/tests/c_backend_wrapper.pyx'
44--- u1db/tests/c_backend_wrapper.pyx 2012-05-21 15:01:18 +0000
45+++ u1db/tests/c_backend_wrapper.pyx 2012-05-21 18:33:19 +0000
46@@ -1027,9 +1027,12 @@
47 # remain valid.
48 new_objs = _list_to_str_array(
49 index_expression, &expressions, &n_expressions)
50- handle_status("create_index",
51- u1db_create_index(self._db, index_name, n_expressions, expressions))
52- free(<void*>expressions)
53+ try:
54+ handle_status("create_index",
55+ u1db_create_index(
56+ self._db, index_name, n_expressions, expressions))
57+ finally:
58+ free(<void*>expressions)
59
60 def list_indexes(self):
61 a_list = []

Subscribers

People subscribed via source and target branches