summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/util/util.c26
-rw-r--r--lib/util/util.h4
2 files changed, 13 insertions, 17 deletions
diff --git a/lib/util/util.c b/lib/util/util.c
index 40ac7f79e6..988d8f9fa0 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -192,34 +192,30 @@ _PUBLIC_ void msleep(unsigned int t)
}
/**
- Get my own name, return in malloc'ed storage.
+ Get my own name, return in talloc'ed storage.
**/
-_PUBLIC_ char *get_myname(void)
+_PUBLIC_ char *get_myname(TALLOC_CTX *ctx)
{
- char *hostname;
char *p;
-
- hostname = (char *)malloc(MAXHOSTNAMELEN+1);
- *hostname = 0;
+ char hostname[HOST_NAME_MAX];
/* get my host name */
- if (gethostname(hostname, MAXHOSTNAMELEN+1) == -1) {
+ if (gethostname(hostname, sizeof(hostname)) == -1) {
DEBUG(0,("gethostname failed\n"));
- free(hostname);
return NULL;
- }
+ }
/* Ensure null termination. */
- hostname[MAXHOSTNAMELEN] = '\0';
+ hostname[sizeof(hostname)-1] = '\0';
/* split off any parts after an initial . */
- p = strchr(hostname, '.');
-
- if (p != NULL)
+ p = strchr_m(hostname, '.');
+ if (p) {
*p = 0;
-
- return hostname;
+ }
+
+ return talloc_strdup(ctx, hostname);
}
/**
diff --git a/lib/util/util.h b/lib/util/util.h
index dced557acb..7873f0e769 100644
--- a/lib/util/util.h
+++ b/lib/util/util.h
@@ -536,9 +536,9 @@ _PUBLIC_ int set_blocking(int fd, bool set);
_PUBLIC_ void msleep(unsigned int t);
/**
- Get my own name, return in malloc'ed storage.
+ Get my own name, return in talloc'ed storage.
**/
-_PUBLIC_ char* get_myname(void);
+_PUBLIC_ char* get_myname(TALLOC_CTX *mem_ctx);
/**
Return true if a string could be a pure IP address.