From: Stephen Hemminger Date: Wed, 12 Aug 2015 15:35:54 +0000 (-0700) Subject: ipnetns: make net namespace cache variable size X-Git-Tag: v4.2.0~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f29d6bb5089271988a820d1f9596f9973ee2e4d;p=thirdparty%2Fiproute2.git ipnetns: make net namespace cache variable size Save some space by using variable size for nsid cache elements. Signed-off-by: Stephen Hemminger --- diff --git a/ip/ipnetns.c b/ip/ipnetns.c index 3b704a454..088096f64 100644 --- a/ip/ipnetns.c +++ b/ip/ipnetns.c @@ -139,7 +139,7 @@ struct nsid_cache { struct hlist_node nsid_hash; struct hlist_node name_hash; int nsid; - char name[NAME_MAX]; + char name[0]; }; #define NSIDMAP_SIZE 128 @@ -164,7 +164,7 @@ static struct nsid_cache *netns_map_get_by_nsid(int nsid) return NULL; } -static int netns_map_add(int nsid, char *name) +static int netns_map_add(int nsid, const char *name) { struct nsid_cache *c; uint32_t h; @@ -172,7 +172,7 @@ static int netns_map_add(int nsid, char *name) if (netns_map_get_by_nsid(nsid) != NULL) return -EEXIST; - c = malloc(sizeof(*c)); + c = malloc(sizeof(*c) + strlen(name)); if (c == NULL) { perror("malloc"); return -ENOMEM;