- m = (mountlist) xmalloc(sizeof(*m));
- m->ml_hostname = xstrdup(rep->r_client);
- m->ml_directory = xstrdup(rep->r_path);
+ m = calloc(1, sizeof(*m));
+ if (m == NULL) {
+ mountlist_freeall(mlist);
+ mlist = NULL;
+ xlog(L_ERROR, "%s: memory allocation failed",
+ __func__);
+ break;
+ }
+
+ if (reverse_resolve) {
+ struct addrinfo *ai;
+ ai = host_pton(rep->r_client);
+ if (ai != NULL) {
+ m->ml_hostname = host_canonname(ai->ai_addr);
+ freeaddrinfo(ai);
+ }
+ }
+ if (m->ml_hostname == NULL)
+ m->ml_hostname = strdup(rep->r_client);
+
+ m->ml_directory = strdup(rep->r_path);
+
+ if (m->ml_hostname == NULL || m->ml_directory == NULL) {
+ mountlist_freeall(mlist);
+ mlist = NULL;
+ xlog(L_ERROR, "%s: memory allocation failed",
+ __func__);
+ break;
+ }
+