MT#61856 main: redis host/port parsing

In case when parsing fails in `redis_ep_parse()`
and it returns -1, we never de-allocate the actually
duplicated strings before (using `g_strdup()`).

For example with redis subscribe, where we have a fallback,
will leak and overwrite previous allocations.

So just free what's been allocated on the failure case.

Change-Id: I340f8998de9de80342f293c669719bea7c3a2a97
mr26.1
Donat Zenichev 1 month ago
parent b659b2371f
commit df32af138f

@ -500,11 +500,17 @@ static bool if_addr_parse(intf_config_q *q, char *s, struct ifaddrs *ifas) {
}
/**
* Sets hostname and auth.
*/
static int redis_ep_parse(endpoint_t *ep, int *db, char **hostname, char **auth, const char *auth_env, char *s) {
char *sl, *sp;
long l;
/* ensure to have pointers nulled */
*auth = NULL;
*hostname = NULL;
sl = strrchr(s, '@');
if (sl) {
*sl = 0;
@ -517,16 +523,14 @@ static int redis_ep_parse(endpoint_t *ep, int *db, char **hostname, char **auth,
if (db) {
sl = strchr(s, '/');
if (!sl)
return -1;
goto error;
*sl = 0;
sl++;
if (!*sl)
return -1;
goto error;
l = strtol(sl, &sl, 10);
if (*sl != 0)
return -1;
if (l < 0)
return -1;
if (*sl != 0 || l < 0)
goto error;
*db = l;
}
@ -538,8 +542,15 @@ static int redis_ep_parse(endpoint_t *ep, int *db, char **hostname, char **auth,
*hostname = g_strdup(s);
if (!endpoint_parse_any_getaddrinfo_full(ep, s))
return -1;
goto error;
return 0;
error:
if (*hostname)
g_free(*hostname);
if (*auth)
g_free(*auth);
return -1;
}

Loading…
Cancel
Save