system/Resolver: use std::string to allocate internal buffer
No GLib memory allocation.
This commit is contained in:
parent
e1901e97c2
commit
0c53e8c2d0
@ -22,8 +22,6 @@
|
|||||||
#include "util/Error.hxx"
|
#include "util/Error.hxx"
|
||||||
#include "util/Domain.hxx"
|
#include "util/Domain.hxx"
|
||||||
|
|
||||||
#include <glib.h>
|
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
@ -107,19 +105,19 @@ resolve_host_port(const char *host_port, unsigned default_port,
|
|||||||
int flags, int socktype,
|
int flags, int socktype,
|
||||||
Error &error)
|
Error &error)
|
||||||
{
|
{
|
||||||
char *p = g_strdup(host_port);
|
std::string p(host_port);
|
||||||
const char *host = p, *port = NULL;
|
const char *host = p.c_str(), *port = nullptr;
|
||||||
|
|
||||||
if (host_port[0] == '[') {
|
if (host_port[0] == '[') {
|
||||||
/* IPv6 needs enclosing square braces, to
|
/* IPv6 needs enclosing square braces, to
|
||||||
differentiate between IP colons and the port
|
differentiate between IP colons and the port
|
||||||
separator */
|
separator */
|
||||||
|
|
||||||
char *q = strchr(p + 1, ']');
|
size_t q = p.find(']', 1);
|
||||||
if (q != NULL && q[1] == ':' && q[2] != 0) {
|
if (q != p.npos && p[q + 1] == ':' && p[q + 2] != 0) {
|
||||||
*q = 0;
|
p[q] = 0;
|
||||||
|
port = host + q + 2;
|
||||||
++host;
|
++host;
|
||||||
port = q + 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,10 +125,11 @@ resolve_host_port(const char *host_port, unsigned default_port,
|
|||||||
/* port is after the colon, but only if it's the only
|
/* port is after the colon, but only if it's the only
|
||||||
colon (don't split IPv6 addresses) */
|
colon (don't split IPv6 addresses) */
|
||||||
|
|
||||||
char *q = strchr(p, ':');
|
auto q = p.find(':');
|
||||||
if (q != NULL && q[1] != 0 && strchr(q + 1, ':') == NULL) {
|
if (q != p.npos && p[q + 1] != 0 &&
|
||||||
*q = 0;
|
p.find(':', q + 1) == p.npos) {
|
||||||
port = q + 1;
|
p[q] = 0;
|
||||||
|
port = host + q + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +150,6 @@ resolve_host_port(const char *host_port, unsigned default_port,
|
|||||||
|
|
||||||
struct addrinfo *ai;
|
struct addrinfo *ai;
|
||||||
int ret = getaddrinfo(host, port, &hints, &ai);
|
int ret = getaddrinfo(host, port, &hints, &ai);
|
||||||
g_free(p);
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
error.Format(resolver_domain, ret,
|
error.Format(resolver_domain, ret,
|
||||||
"Failed to look up '%s': %s",
|
"Failed to look up '%s': %s",
|
||||||
|
Loading…
Reference in New Issue
Block a user