Replace malloc() + memset() with calloc. This corrects a misuse of
memset() as a side effect.
This commit is contained in:
parent
59e2759db8
commit
9bbd8028fa
@ -140,9 +140,8 @@ group_lookup_func(const char *key, size_t key_size, char **buffer,
|
||||
switch (lookup_type) {
|
||||
case nss_lt_name:
|
||||
size = key_size - sizeof(enum nss_lookup_type) + 1;
|
||||
name = (char *)malloc(size);
|
||||
name = (char *)calloc(1, size);
|
||||
assert(name != NULL);
|
||||
memset(name, 0, size);
|
||||
memcpy(name, key + sizeof(enum nss_lookup_type), size - 1);
|
||||
break;
|
||||
case nss_lt_id:
|
||||
@ -225,9 +224,8 @@ init_group_agent()
|
||||
struct common_agent *retval;
|
||||
|
||||
TRACE_IN(init_group_agent);
|
||||
retval = (struct common_agent *)malloc(sizeof(struct common_agent));
|
||||
retval = (struct common_agent *)calloc(1, sizeof(struct common_agent));
|
||||
assert(retval != NULL);
|
||||
memset(retval, 0, sizeof(struct common_agent));
|
||||
|
||||
retval->parent.name = strdup("group");
|
||||
assert(retval->parent.name != NULL);
|
||||
@ -245,10 +243,9 @@ init_group_mp_agent()
|
||||
struct multipart_agent *retval;
|
||||
|
||||
TRACE_IN(init_group_mp_agent);
|
||||
retval = (struct multipart_agent *)malloc(
|
||||
retval = (struct multipart_agent *)calloc(1,
|
||||
sizeof(struct multipart_agent));
|
||||
assert(retval != NULL);
|
||||
memset(retval, 0, sizeof(struct multipart_agent));
|
||||
|
||||
retval->parent.name = strdup("group");
|
||||
retval->parent.type = MULTIPART_AGENT;
|
||||
|
@ -148,9 +148,8 @@ passwd_lookup_func(const char *key, size_t key_size, char **buffer,
|
||||
switch (lookup_type) {
|
||||
case nss_lt_name:
|
||||
size = key_size - sizeof(enum nss_lookup_type) + 1;
|
||||
login = (char *)malloc(size);
|
||||
login = (char *)calloc(1, size);
|
||||
assert(login != NULL);
|
||||
memset(login, 0, size);
|
||||
memcpy(login, key + sizeof(enum nss_lookup_type), size - 1);
|
||||
break;
|
||||
case nss_lt_id:
|
||||
@ -232,9 +231,8 @@ init_passwd_agent()
|
||||
struct common_agent *retval;
|
||||
|
||||
TRACE_IN(init_passwd_agent);
|
||||
retval = (struct common_agent *)malloc(sizeof(struct common_agent));
|
||||
retval = (struct common_agent *)calloc(1, sizeof(struct common_agent));
|
||||
assert(retval != NULL);
|
||||
memset(retval, 0, sizeof(struct common_agent));
|
||||
|
||||
retval->parent.name = strdup("passwd");
|
||||
assert(retval->parent.name != NULL);
|
||||
@ -252,10 +250,9 @@ init_passwd_mp_agent()
|
||||
struct multipart_agent *retval;
|
||||
|
||||
TRACE_IN(init_passwd_mp_agent);
|
||||
retval = (struct multipart_agent *)malloc(
|
||||
retval = (struct multipart_agent *)calloc(1,
|
||||
sizeof(struct multipart_agent));
|
||||
assert(retval != NULL);
|
||||
memset(retval, 0, sizeof(struct multipart_agent));
|
||||
|
||||
retval->parent.name = strdup("passwd");
|
||||
retval->parent.type = MULTIPART_AGENT;
|
||||
|
@ -145,9 +145,8 @@ services_lookup_func(const char *key, size_t key_size, char **buffer,
|
||||
switch (lookup_type) {
|
||||
case nss_lt_name:
|
||||
size = key_size - sizeof(enum nss_lookup_type);
|
||||
name = (char *)malloc(size + 1);
|
||||
name = (char *)calloc(1, size + 1);
|
||||
assert(name != NULL);
|
||||
memset(name, 0, size + 1);
|
||||
memcpy(name, key + sizeof(enum nss_lookup_type), size);
|
||||
|
||||
size2 = strlen(name) + 1;
|
||||
@ -169,9 +168,8 @@ services_lookup_func(const char *key, size_t key_size, char **buffer,
|
||||
|
||||
size = key_size - sizeof(enum nss_lookup_type) - sizeof(int);
|
||||
if (size > 0) {
|
||||
proto = (char *)malloc(size + 1);
|
||||
proto = (char *)calloc(1, size + 1);
|
||||
assert(proto != NULL);
|
||||
memset(proto, size + 1, 0);
|
||||
memcpy(proto, key + sizeof(enum nss_lookup_type) +
|
||||
sizeof(int), size);
|
||||
}
|
||||
@ -247,9 +245,8 @@ init_services_agent()
|
||||
struct common_agent *retval;
|
||||
TRACE_IN(init_services_agent);
|
||||
|
||||
retval = (struct common_agent *)malloc(sizeof(struct common_agent));
|
||||
retval = (struct common_agent *)calloc(1, sizeof(struct common_agent));
|
||||
assert(retval != NULL);
|
||||
memset(retval, 0, sizeof(struct common_agent));
|
||||
|
||||
retval->parent.name = strdup("services");
|
||||
assert(retval->parent.name != NULL);
|
||||
@ -267,10 +264,9 @@ init_services_mp_agent()
|
||||
struct multipart_agent *retval;
|
||||
|
||||
TRACE_IN(init_services_mp_agent);
|
||||
retval = (struct multipart_agent *)malloc(
|
||||
retval = (struct multipart_agent *)calloc(1,
|
||||
sizeof(struct multipart_agent));
|
||||
assert(retval != NULL);
|
||||
memset(retval, 0, sizeof(struct multipart_agent));
|
||||
|
||||
retval->parent.name = strdup("services");
|
||||
retval->parent.type = MULTIPART_AGENT;
|
||||
|
Loading…
Reference in New Issue
Block a user