Skip to content

Commit 5fa8774

Browse files
committed
Fix memory leak in mongoc_uri_parse_option
1 parent c8ea305 commit 5fa8774

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/mongoc/mongoc-uri.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -494,18 +494,19 @@ mongoc_uri_parse_option (mongoc_uri_t *uri,
494494
{
495495
int32_t v_int;
496496
const char *end_key;
497-
char *key;
498-
char *value;
497+
char *key = NULL;
498+
char *value = NULL;
499+
bool ret = false;
499500

500501
if (!(key = scan_to_unichar(str, '=', "", &end_key))) {
501-
return false;
502+
goto CLEANUP;
502503
}
503504

504505
value = bson_strdup(end_key + 1);
505506
mongoc_uri_do_unescape(&value);
506507
if (!value) {
507508
/* do_unescape detected invalid UTF-8 and freed value */
508-
return false;
509+
goto CLEANUP;
509510
}
510511

511512
if (!strcasecmp(key, "connecttimeoutms") ||
@@ -543,18 +544,19 @@ mongoc_uri_parse_option (mongoc_uri_t *uri,
543544
bson_append_utf8(&uri->credentials, key, -1, value, -1);
544545
} else if (!strcasecmp(key, "authmechanismproperties")) {
545546
if (!mongoc_uri_parse_auth_mechanism_properties(uri, value)) {
546-
bson_free(key);
547-
bson_free(value);
548-
return false;
547+
goto CLEANUP;
549548
}
550549
} else {
551550
bson_append_utf8(&uri->options, key, -1, value, -1);
552551
}
553552

553+
ret = true;
554+
555+
CLEANUP:
554556
bson_free(key);
555557
bson_free(value);
556558

557-
return true;
559+
return ret;
558560
}
559561

560562

0 commit comments

Comments
 (0)