Skip to content

Commit d75dfca

Browse files
committed
fix cache leak
1 parent 63a51e8 commit d75dfca

File tree

3 files changed

+39
-49
lines changed

3 files changed

+39
-49
lines changed

src/libmongoc/src/mongoc/mongoc-ocsp-cache.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,8 @@ _mongoc_ocsp_cache_get_status (OCSP_CERTID *id,
174174

175175
*cert_status = entry->cert_status;
176176
*reason = entry->reason;
177-
*this_update =
178-
ASN1_item_dup (ASN1_ITEM_rptr (ASN1_TIME), entry->this_update);
179-
*next_update =
180-
ASN1_item_dup (ASN1_ITEM_rptr (ASN1_TIME), entry->next_update);
177+
*this_update = entry->this_update;
178+
*next_update = entry->next_update;
181179

182180
ret = true;
183181
done:

src/libmongoc/src/mongoc/mongoc-openssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ _contact_ocsp_responder (OCSP_CERTID *id, X509 *peer)
658658
{
659659
STACK_OF (OPENSSL_STRING) *url_stack = NULL;
660660
OPENSSL_STRING url = NULL, host = NULL, path = NULL, port = NULL;
661-
OCSP_REQUEST *req;
661+
OCSP_REQUEST *req = NULL;
662662
OCSP_REQ_CTX *sendreq_ctx = NULL;
663663
OCSP_RESPONSE *resp = NULL;
664664
BIO *bio = NULL;

src/libmongoc/tests/test-mongoc-ocsp-cache.c

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -60,129 +60,121 @@ create_cert_id (long serial)
6060
static void
6161
test_mongoc_cache_insert (void)
6262
{
63-
ASN1_GENERALIZEDTIME *this_update, *next_update;
63+
ASN1_GENERALIZEDTIME *this_update_in, *next_update_in;
64+
ASN1_GENERALIZEDTIME *this_update_out, *next_update_out;
6465
int i, size = 5, status = V_OCSP_CERTSTATUS_GOOD,
6566
reason = OCSP_REVOKED_STATUS_NOSTATUS;
6667

6768
CLEAR_CACHE;
6869

69-
next_update = ASN1_GENERALIZEDTIME_set (NULL, time (NULL) + 999);
70-
this_update = ASN1_GENERALIZEDTIME_set (NULL, time (NULL));
70+
next_update_in = ASN1_GENERALIZEDTIME_set (NULL, time (NULL) + 999);
71+
this_update_in = ASN1_GENERALIZEDTIME_set (NULL, time (NULL));
7172
for (i = 0; i < size; i++) {
72-
ASN1_GENERALIZEDTIME *thisupd, *nextupd;
7373
int s, r;
7474
OCSP_CERTID *id = create_cert_id (i);
7575

76-
BSON_ASSERT (
77-
!_mongoc_ocsp_cache_get_status (id, &s, &r, &thisupd, &nextupd));
76+
BSON_ASSERT (!_mongoc_ocsp_cache_get_status (
77+
id, &s, &r, &this_update_out, &next_update_out));
7878
_mongoc_ocsp_cache_set_resp (
79-
id, status, reason, this_update, next_update);
79+
id, status, reason, this_update_in, next_update_in);
8080

8181
OCSP_CERTID_free (id);
8282
}
8383

8484
BSON_ASSERT (_mongoc_ocsp_cache_length () == size);
8585

8686
for (i = 0; i < size; i++) {
87-
ASN1_GENERALIZEDTIME *thisupd, *nextupd;
8887
OCSP_CERTID *id = create_cert_id (i);
8988
int s, r;
9089

91-
BSON_ASSERT (
92-
_mongoc_ocsp_cache_get_status (id, &s, &r, &thisupd, &nextupd));
90+
BSON_ASSERT (_mongoc_ocsp_cache_get_status (
91+
id, &s, &r, &this_update_out, &next_update_out));
9392

9493
BSON_ASSERT (status == s);
9594
BSON_ASSERT (reason == r);
96-
ASSERT_TIME_EQUAL (next_update, nextupd);
97-
ASSERT_TIME_EQUAL (this_update, thisupd);
95+
ASSERT_TIME_EQUAL (next_update_in, next_update_out);
96+
ASSERT_TIME_EQUAL (this_update_in, this_update_out);
9897

99-
ASN1_GENERALIZEDTIME_free (thisupd);
100-
ASN1_GENERALIZEDTIME_free (nextupd);
10198
OCSP_CERTID_free (id);
10299
}
103100

104-
ASN1_GENERALIZEDTIME_free (next_update);
105-
ASN1_GENERALIZEDTIME_free (this_update);
106101
CLEAR_CACHE;
102+
ASN1_GENERALIZEDTIME_free (this_update_in);
103+
ASN1_GENERALIZEDTIME_free (next_update_in);
107104
}
108105

109106
static void
110107
test_mongoc_cache_update (void)
111108
{
112109
OCSP_CERTID *id;
113-
ASN1_GENERALIZEDTIME *next_update, *nextupd, *thisupd;
110+
ASN1_GENERALIZEDTIME *next_update_in, *next_update_out, *this_update_out;
114111
int status, reason;
115112

116113
CLEAR_CACHE;
117114

118-
next_update = ASN1_GENERALIZEDTIME_set (NULL, time (NULL));
115+
next_update_in = ASN1_GENERALIZEDTIME_set (NULL, time (NULL));
119116
id = create_cert_id (1);
120117

121118
_mongoc_ocsp_cache_set_resp (
122-
id, V_OCSP_CERTSTATUS_GOOD, 0, NULL, next_update);
119+
id, V_OCSP_CERTSTATUS_GOOD, 0, NULL, next_update_in);
123120
BSON_ASSERT (_mongoc_ocsp_cache_length () == 1);
124121

125-
BSON_ASSERT (
126-
_mongoc_ocsp_cache_get_status (id, &status, &reason, &thisupd, &nextupd));
122+
BSON_ASSERT (_mongoc_ocsp_cache_get_status (
123+
id, &status, &reason, &this_update_out, &next_update_out));
127124
BSON_ASSERT (status == V_OCSP_CERTSTATUS_GOOD);
128125

129-
ASN1_GENERALIZEDTIME_free (next_update);
130-
next_update = ASN1_GENERALIZEDTIME_set (
126+
ASN1_GENERALIZEDTIME_free (next_update_in);
127+
next_update_in = ASN1_GENERALIZEDTIME_set (
131128
NULL, time (NULL) + 999 /* some time in the future */);
132129

133130
_mongoc_ocsp_cache_set_resp (
134-
id, V_OCSP_CERTSTATUS_REVOKED, 0, NULL, next_update);
131+
id, V_OCSP_CERTSTATUS_REVOKED, 0, NULL, next_update_in);
135132
BSON_ASSERT (_mongoc_ocsp_cache_length () == 1);
136133

137-
ASN1_GENERALIZEDTIME_free (nextupd);
138-
ASN1_GENERALIZEDTIME_free (thisupd);
139-
BSON_ASSERT (
140-
_mongoc_ocsp_cache_get_status (id, &status, &reason, &thisupd, &nextupd));
134+
BSON_ASSERT (_mongoc_ocsp_cache_get_status (
135+
id, &status, &reason, &this_update_out, &next_update_out));
141136
BSON_ASSERT (status == V_OCSP_CERTSTATUS_REVOKED);
142137

143-
ASN1_GENERALIZEDTIME_free (next_update);
144-
next_update = ASN1_GENERALIZEDTIME_set (
138+
ASN1_GENERALIZEDTIME_free (next_update_in);
139+
next_update_in = ASN1_GENERALIZEDTIME_set (
145140
NULL, time (NULL) - 999 /* some time in the past */);
146141

147142
_mongoc_ocsp_cache_set_resp (
148-
id, V_OCSP_CERTSTATUS_GOOD, 0, NULL, next_update);
143+
id, V_OCSP_CERTSTATUS_GOOD, 0, NULL, next_update_in);
149144
BSON_ASSERT (_mongoc_ocsp_cache_length () == 1);
150145

151-
ASN1_GENERALIZEDTIME_free (nextupd);
152-
ASN1_GENERALIZEDTIME_free (thisupd);
153-
BSON_ASSERT (
154-
_mongoc_ocsp_cache_get_status (id, &status, &reason, &thisupd, &nextupd));
146+
BSON_ASSERT (_mongoc_ocsp_cache_get_status (
147+
id, &status, &reason, &this_update_out, &next_update_out));
155148
BSON_ASSERT (status == V_OCSP_CERTSTATUS_REVOKED);
156149

157150
CLEAR_CACHE;
158151

159-
ASN1_GENERALIZEDTIME_free (nextupd);
160-
ASN1_GENERALIZEDTIME_free (thisupd);
161-
ASN1_GENERALIZEDTIME_free (next_update);
152+
ASN1_GENERALIZEDTIME_free (next_update_in);
162153
OCSP_CERTID_free (id);
163154
}
164155

165156
static void
166157
test_mongoc_cache_remove_expired_cert (void)
167158
{
168-
ASN1_GENERALIZEDTIME *this_update, *next_update;
159+
ASN1_GENERALIZEDTIME *this_update_in, *next_update_in;
169160
int status = V_OCSP_CERTSTATUS_GOOD, reason = OCSP_REVOKED_STATUS_NOSTATUS;
170161
OCSP_CERTID *id = create_cert_id (1);
171162

172163
CLEAR_CACHE;
173164

174-
next_update = ASN1_GENERALIZEDTIME_set (NULL, time (NULL) - 1);
175-
this_update = ASN1_GENERALIZEDTIME_set (NULL, time (NULL) - 999);
165+
next_update_in = ASN1_GENERALIZEDTIME_set (NULL, time (NULL) - 1);
166+
this_update_in = ASN1_GENERALIZEDTIME_set (NULL, time (NULL) - 999);
176167

177-
_mongoc_ocsp_cache_set_resp (id, status, reason, this_update, next_update);
168+
_mongoc_ocsp_cache_set_resp (
169+
id, status, reason, this_update_in, next_update_in);
178170

179171
BSON_ASSERT (_mongoc_ocsp_cache_length () == 1);
180172
BSON_ASSERT (!_mongoc_ocsp_cache_get_status (id, NULL, NULL, NULL, NULL));
181173
BSON_ASSERT (_mongoc_ocsp_cache_length () == 0);
182174

183175
OCSP_CERTID_free (id);
184-
ASN1_GENERALIZEDTIME_free (next_update);
185-
ASN1_GENERALIZEDTIME_free (this_update);
176+
ASN1_GENERALIZEDTIME_free (next_update_in);
177+
ASN1_GENERALIZEDTIME_free (this_update_in);
186178

187179
CLEAR_CACHE;
188180
}

0 commit comments

Comments
 (0)