* [PATCH 0/4] Four more pre-requisites for mountd IPv6 support
@ 2010-04-19 20:20 Chuck Lever
[not found] ` <20100419201855.3567.9644.stgit-RytpoXr2tKZ9HhUboXbp9zCvJB+x5qRC@public.gmane.org>
2010-04-23 16:29 ` Steve Dickson
0 siblings, 2 replies; 7+ messages in thread
From: Chuck Lever @ 2010-04-19 20:20 UTC (permalink / raw)
To: steved; +Cc: linux-nfs
Hi Steve-
These patches clean up some memory allocation nits in libexport.a.
They pave the way for parsing IPv6 addresses and netmasks in
client_init().
---
Chuck Lever (4):
libexport.a: Allow malloc(3) failures in client_lookup() and friends
libexport.a: Allow m_hostname allocation to fail instead of exit
libexport.a: Allow client_init() to fail instead of exit
libexport.a: Add client_free()
support/export/client.c | 55 +++++++++++++++++++++++++++++++----------------
1 files changed, 36 insertions(+), 19 deletions(-)
--
Chuck Lever
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/4] libexport.a: Add client_free()
[not found] ` <20100419201855.3567.9644.stgit-RytpoXr2tKZ9HhUboXbp9zCvJB+x5qRC@public.gmane.org>
@ 2010-04-19 20:21 ` Chuck Lever
2010-04-19 20:21 ` [PATCH 2/4] libexport.a: Allow client_init() to fail instead of exit Chuck Lever
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Chuck Lever @ 2010-04-19 20:21 UTC (permalink / raw)
To: steved; +Cc: linux-nfs
Clean up: Introduce a helper to free a nfs_client record.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
support/export/client.c | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/support/export/client.c b/support/export/client.c
index 6a25928..859dcf1 100644
--- a/support/export/client.c
+++ b/support/export/client.c
@@ -52,6 +52,13 @@ init_addrlist(nfs_client *clp, const struct hostent *hp)
clp->m_naddr = i;
}
+static void
+client_free(nfs_client *clp)
+{
+ xfree(clp->m_hostname);
+ xfree(clp);
+}
+
/* if canonical is set, then we *know* this is already a canonical name
* so hostname lookup is avoided.
* This is used when reading /proc/fs/nfs/exports
@@ -209,8 +216,7 @@ client_freeall(void)
head = clientlist + i;
while (*head) {
*head = (clp = *head)->m_next;
- xfree(clp->m_hostname);
- xfree(clp);
+ client_free(clp);
}
}
}
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/4] libexport.a: Allow client_init() to fail instead of exit
[not found] ` <20100419201855.3567.9644.stgit-RytpoXr2tKZ9HhUboXbp9zCvJB+x5qRC@public.gmane.org>
2010-04-19 20:21 ` [PATCH 1/4] libexport.a: Add client_free() Chuck Lever
@ 2010-04-19 20:21 ` Chuck Lever
2010-04-19 20:21 ` [PATCH 3/4] libexport.a: Allow m_hostname allocation " Chuck Lever
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Chuck Lever @ 2010-04-19 20:21 UTC (permalink / raw)
To: steved; +Cc: linux-nfs
client_init()'s current callers can now deal correctly with a failure.
Get rid of code that can cause our process to exit in client_init(),
if address mask parsing or memory allocation fails.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
support/export/client.c | 24 +++++++++++++++++-------
1 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/support/export/client.c b/support/export/client.c
index 859dcf1..8f83da3 100644
--- a/support/export/client.c
+++ b/support/export/client.c
@@ -30,7 +30,7 @@ extern int innetgr(char *netgr, char *host, char *, char *);
#endif
static char *add_name(char *old, const char *add);
-static void client_init(nfs_client *clp, const char *hname,
+static int client_init(nfs_client *clp, const char *hname,
struct hostent *hp);
nfs_client *clientlist[MCL_MAXTYPES] = { NULL, };
@@ -115,13 +115,18 @@ client_lookup(char *hname, int canonical)
clp = (nfs_client *) xmalloc(sizeof(*clp));
memset(clp, 0, sizeof(*clp));
clp->m_type = htype;
- client_init(clp, hname, NULL);
+ if (!client_init(clp, hname, NULL)) {
+ client_free(clp);
+ clp = NULL;
+ goto out;
+ }
client_add(clp);
}
if (htype == MCL_FQDN && clp->m_naddr == 0)
init_addrlist(clp, hp);
+out:
if (hp)
free (hp);
@@ -138,12 +143,15 @@ client_dup(nfs_client *clp, struct hostent *hp)
new->m_type = MCL_FQDN;
new->m_hostname = NULL;
- client_init(new, (char *) hp->h_name, hp);
+ if (!client_init(new, hp->h_name, hp)) {
+ client_free(new);
+ return NULL;
+ }
client_add(new);
return new;
}
-static void
+static int
client_init(nfs_client *clp, const char *hname, struct hostent *hp)
{
xfree(clp->m_hostname);
@@ -173,15 +181,17 @@ client_init(nfs_client *clp, const char *hname, struct hostent *hp)
htonl ((uint32_t) ~0 << (32 - netmask));
}
else {
- xlog(L_FATAL, "invalid netmask `%s' for %s",
- cp + 1, clp->m_hostname);
+ xlog(L_ERROR, "invalid netmask `%s' for %s",
+ cp + 1, clp->m_hostname);
+ return 0;
}
}
*cp = '/';
- return;
+ return 1;
}
init_addrlist(clp, hp);
+ return 1;
}
void
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/4] libexport.a: Allow m_hostname allocation to fail instead of exit
[not found] ` <20100419201855.3567.9644.stgit-RytpoXr2tKZ9HhUboXbp9zCvJB+x5qRC@public.gmane.org>
2010-04-19 20:21 ` [PATCH 1/4] libexport.a: Add client_free() Chuck Lever
2010-04-19 20:21 ` [PATCH 2/4] libexport.a: Allow client_init() to fail instead of exit Chuck Lever
@ 2010-04-19 20:21 ` Chuck Lever
2010-04-19 20:21 ` [PATCH 4/4] libexport.a: Allow malloc(3) failures in client_lookup() and friends Chuck Lever
2010-04-20 12:16 ` [PATCH 0/4] Four more pre-requisites for mountd IPv6 support Jeff Layton
4 siblings, 0 replies; 7+ messages in thread
From: Chuck Lever @ 2010-04-19 20:21 UTC (permalink / raw)
To: steved; +Cc: linux-nfs
Clean up: Replace xstrdup() with strdup(3) in client_init(), to
prevent the process from exiting if the memory allocation fails.
Note that both of client_init()'s callers set m_hostname equal to NULL
before calling, thus the extra free(3) at the top of client_init() is
unneeded.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
support/export/client.c | 10 ++++------
1 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/support/export/client.c b/support/export/client.c
index 8f83da3..fc1ade9 100644
--- a/support/export/client.c
+++ b/support/export/client.c
@@ -55,7 +55,7 @@ init_addrlist(nfs_client *clp, const struct hostent *hp)
static void
client_free(nfs_client *clp)
{
- xfree(clp->m_hostname);
+ free(clp->m_hostname);
xfree(clp);
}
@@ -154,11 +154,9 @@ client_dup(nfs_client *clp, struct hostent *hp)
static int
client_init(nfs_client *clp, const char *hname, struct hostent *hp)
{
- xfree(clp->m_hostname);
- if (hp)
- clp->m_hostname = xstrdup(hp->h_name);
- else
- clp->m_hostname = xstrdup(hname);
+ clp->m_hostname = strdup(hname);
+ if (clp->m_hostname == NULL)
+ return false;
clp->m_exported = 0;
clp->m_count = 0;
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/4] libexport.a: Allow malloc(3) failures in client_lookup() and friends
[not found] ` <20100419201855.3567.9644.stgit-RytpoXr2tKZ9HhUboXbp9zCvJB+x5qRC@public.gmane.org>
` (2 preceding siblings ...)
2010-04-19 20:21 ` [PATCH 3/4] libexport.a: Allow m_hostname allocation " Chuck Lever
@ 2010-04-19 20:21 ` Chuck Lever
2010-04-20 12:16 ` [PATCH 0/4] Four more pre-requisites for mountd IPv6 support Jeff Layton
4 siblings, 0 replies; 7+ messages in thread
From: Chuck Lever @ 2010-04-19 20:21 UTC (permalink / raw)
To: steved; +Cc: linux-nfs
Clean up: Use malloc(3) instead of xmalloc() in client_lookup() and
client_dup(), ensuring that a failed memory allocation here doesn't
cause our process to exit suddenly.
Allocation of nfs_client records and the m_hostname string are now
consistently handled with malloc(3), calloc(3), strdup(3), and
free(3).
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
support/export/client.c | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/support/export/client.c b/support/export/client.c
index fc1ade9..3b3a898 100644
--- a/support/export/client.c
+++ b/support/export/client.c
@@ -17,7 +17,7 @@
#include <string.h>
#include <ctype.h>
#include <netdb.h>
-#include "xmalloc.h"
+
#include "misc.h"
#include "nfslib.h"
#include "exportfs.h"
@@ -56,7 +56,7 @@ static void
client_free(nfs_client *clp)
{
free(clp->m_hostname);
- xfree(clp);
+ free(clp);
}
/* if canonical is set, then we *know* this is already a canonical name
@@ -111,9 +111,10 @@ client_lookup(char *hname, int canonical)
}
}
- if (!clp) {
- clp = (nfs_client *) xmalloc(sizeof(*clp));
- memset(clp, 0, sizeof(*clp));
+ if (clp == NULL) {
+ clp = calloc(1, sizeof(*clp));
+ if (clp == NULL)
+ goto out;
clp->m_type = htype;
if (!client_init(clp, hname, NULL)) {
client_free(clp);
@@ -138,7 +139,9 @@ client_dup(nfs_client *clp, struct hostent *hp)
{
nfs_client *new;
- new = (nfs_client *) xmalloc(sizeof(*new));
+ new = (nfs_client *)malloc(sizeof(*new));
+ if (new == NULL)
+ return NULL;
memcpy(new, clp, sizeof(*new));
new->m_type = MCL_FQDN;
new->m_hostname = NULL;
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/4] Four more pre-requisites for mountd IPv6 support
[not found] ` <20100419201855.3567.9644.stgit-RytpoXr2tKZ9HhUboXbp9zCvJB+x5qRC@public.gmane.org>
` (3 preceding siblings ...)
2010-04-19 20:21 ` [PATCH 4/4] libexport.a: Allow malloc(3) failures in client_lookup() and friends Chuck Lever
@ 2010-04-20 12:16 ` Jeff Layton
4 siblings, 0 replies; 7+ messages in thread
From: Jeff Layton @ 2010-04-20 12:16 UTC (permalink / raw)
To: Chuck Lever; +Cc: steved, linux-nfs
On Mon, 19 Apr 2010 16:20:51 -0400
Chuck Lever <chuck.lever@oracle.com> wrote:
> Hi Steve-
>
> These patches clean up some memory allocation nits in libexport.a.
> They pave the way for parsing IPv6 addresses and netmasks in
> client_init().
>
> ---
>
> Chuck Lever (4):
> libexport.a: Allow malloc(3) failures in client_lookup() and friends
> libexport.a: Allow m_hostname allocation to fail instead of exit
> libexport.a: Allow client_init() to fail instead of exit
> libexport.a: Add client_free()
>
>
> support/export/client.c | 55 +++++++++++++++++++++++++++++++----------------
> 1 files changed, 36 insertions(+), 19 deletions(-)
>
These look good to me.
Reviewed-by: Jeff Layton <jlayton@redhat.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/4] Four more pre-requisites for mountd IPv6 support
2010-04-19 20:20 [PATCH 0/4] Four more pre-requisites for mountd IPv6 support Chuck Lever
[not found] ` <20100419201855.3567.9644.stgit-RytpoXr2tKZ9HhUboXbp9zCvJB+x5qRC@public.gmane.org>
@ 2010-04-23 16:29 ` Steve Dickson
1 sibling, 0 replies; 7+ messages in thread
From: Steve Dickson @ 2010-04-23 16:29 UTC (permalink / raw)
To: Chuck Lever; +Cc: linux-nfs
On 04/19/2010 04:20 PM, Chuck Lever wrote:
> Hi Steve-
>
> These patches clean up some memory allocation nits in libexport.a.
> They pave the way for parsing IPv6 addresses and netmasks in
> client_init().
>
> ---
>
> Chuck Lever (4):
> libexport.a: Allow malloc(3) failures in client_lookup() and friends
> libexport.a: Allow m_hostname allocation to fail instead of exit
> libexport.a: Allow client_init() to fail instead of exit
> libexport.a: Add client_free()
>
>
> support/export/client.c | 55 +++++++++++++++++++++++++++++++----------------
> 1 files changed, 36 insertions(+), 19 deletions(-)
>
All four committed...
steved.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-04-23 17:16 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-19 20:20 [PATCH 0/4] Four more pre-requisites for mountd IPv6 support Chuck Lever
[not found] ` <20100419201855.3567.9644.stgit-RytpoXr2tKZ9HhUboXbp9zCvJB+x5qRC@public.gmane.org>
2010-04-19 20:21 ` [PATCH 1/4] libexport.a: Add client_free() Chuck Lever
2010-04-19 20:21 ` [PATCH 2/4] libexport.a: Allow client_init() to fail instead of exit Chuck Lever
2010-04-19 20:21 ` [PATCH 3/4] libexport.a: Allow m_hostname allocation " Chuck Lever
2010-04-19 20:21 ` [PATCH 4/4] libexport.a: Allow malloc(3) failures in client_lookup() and friends Chuck Lever
2010-04-20 12:16 ` [PATCH 0/4] Four more pre-requisites for mountd IPv6 support Jeff Layton
2010-04-23 16:29 ` Steve Dickson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox