malloc data size, not pointer size

This commit is contained in:
Roy Marples 2007-10-11 23:17:53 +00:00
parent 14287ddd80
commit e3bc6666d6
5 changed files with 25 additions and 25 deletions

View File

@ -311,21 +311,21 @@ bool rc_service_daemon_set (const char *service, const char *exec,
if (exec) { if (exec) {
i = strlen (exec) + 6; i = strlen (exec) + 6;
mexec = xmalloc (sizeof (char *) * i); mexec = xmalloc (sizeof (char) * i);
snprintf (mexec, i, "exec=%s", exec); snprintf (mexec, i, "exec=%s", exec);
} else } else
mexec = xstrdup ("exec="); mexec = xstrdup ("exec=");
if (name) { if (name) {
i = strlen (name) + 6; i = strlen (name) + 6;
mname = xmalloc (sizeof (char *) * i); mname = xmalloc (sizeof (char) * i);
snprintf (mname, i, "name=%s", name); snprintf (mname, i, "name=%s", name);
} else } else
mname = xstrdup ("name="); mname = xstrdup ("name=");
if (pidfile) { if (pidfile) {
i = strlen (pidfile) + 9; i = strlen (pidfile) + 9;
mpidfile = xmalloc (sizeof (char *) * i); mpidfile = xmalloc (sizeof (char) * i);
snprintf (mpidfile, i, "pidfile=%s", pidfile); snprintf (mpidfile, i, "pidfile=%s", pidfile);
} else } else
mpidfile = xstrdup ("pidfile="); mpidfile = xstrdup ("pidfile=");
@ -404,11 +404,11 @@ bool rc_service_started_daemon (const char *service, const char *exec,
free (svc); free (svc);
i = strlen (exec) + 6; i = strlen (exec) + 6;
mexec = xmalloc (sizeof (char *) * i); mexec = xmalloc (sizeof (char) * i);
snprintf (mexec, i, "exec=%s", exec); snprintf (mexec, i, "exec=%s", exec);
if (indx > 0) { if (indx > 0) {
int len = sizeof (char *) * 10; int len = sizeof (char) * 10;
file = xmalloc (len); file = xmalloc (len);
snprintf (file, len, "%03d", indx); snprintf (file, len, "%03d", indx);
retval = _match_daemon (dirpath, file, mexec, NULL, NULL); retval = _match_daemon (dirpath, file, mexec, NULL, NULL);

View File

@ -58,7 +58,7 @@ char *rc_strcatpaths (const char *path1, const char *paths, ...)
} }
va_end (ap); va_end (ap);
pathp = path = xmalloc (length * sizeof (char *)); pathp = path = xmalloc (length * sizeof (char));
memset (path, 0, length); memset (path, 0, length);
i = strlen (path1); i = strlen (path1);
memcpy (path, path1, i); memcpy (path, path1, i);

View File

@ -68,7 +68,7 @@ char **env_filter (void)
if (! env_var && profile) { if (! env_var && profile) {
env_len = strlen (env_name) + strlen ("export ") + 1; env_len = strlen (env_name) + strlen ("export ") + 1;
p = xmalloc (sizeof (char *) * env_len); p = xmalloc (sizeof (char) * env_len);
snprintf (p, env_len, "export %s", env_name); snprintf (p, env_len, "export %s", env_name);
env_var = rc_config_value (profile, p); env_var = rc_config_value (profile, p);
free (p); free (p);
@ -84,7 +84,7 @@ char **env_filter (void)
{ {
got_path = true; got_path = true;
env_len = strlen (env_name) + strlen (env_var) + pplen + 2; env_len = strlen (env_name) + strlen (env_var) + pplen + 2;
e = p = xmalloc (sizeof (char *) * env_len); e = p = xmalloc (sizeof (char) * env_len);
p += snprintf (e, env_len, "%s=%s", env_name, PATH_PREFIX); p += snprintf (e, env_len, "%s=%s", env_name, PATH_PREFIX);
/* Now go through the env var and only add bits not in our PREFIX */ /* Now go through the env var and only add bits not in our PREFIX */
@ -103,7 +103,7 @@ char **env_filter (void)
*p++ = 0; *p++ = 0;
} else { } else {
env_len = strlen (env_name) + strlen (env_var) + 2; env_len = strlen (env_name) + strlen (env_var) + 2;
e = xmalloc (sizeof (char *) * env_len); e = xmalloc (sizeof (char) * env_len);
snprintf (e, env_len, "%s=%s", env_name, env_var); snprintf (e, env_len, "%s=%s", env_name, env_var);
} }
@ -115,7 +115,7 @@ char **env_filter (void)
However, we do need a path, so use a default. */ However, we do need a path, so use a default. */
if (! got_path) { if (! got_path) {
env_len = strlen ("PATH=") + strlen (PATH_PREFIX) + 2; env_len = strlen ("PATH=") + strlen (PATH_PREFIX) + 2;
p = xmalloc (sizeof (char *) * env_len); p = xmalloc (sizeof (char) * env_len);
snprintf (p, env_len, "PATH=%s", PATH_PREFIX); snprintf (p, env_len, "PATH=%s", PATH_PREFIX);
rc_strlist_add (&env, p); rc_strlist_add (&env, p);
free (p); free (p);
@ -197,7 +197,7 @@ char **env_config (void)
rc_strlist_add (&env, line); rc_strlist_add (&env, line);
} else { } else {
int len = strlen (line) + strlen (e) + 2; int len = strlen (line) + strlen (e) + 2;
char *new = xmalloc (sizeof (char *) * len); char *new = xmalloc (sizeof (char) * len);
snprintf (new, len, "%s=%s", line, e); snprintf (new, len, "%s=%s", line, e);
rc_strlist_add (&env, new); rc_strlist_add (&env, new);
free (new); free (new);
@ -207,14 +207,14 @@ char **env_config (void)
/* One char less to drop the trailing / */ /* One char less to drop the trailing / */
i = strlen ("RC_LIBDIR=") + strlen (RC_LIBDIR) + 1; i = strlen ("RC_LIBDIR=") + strlen (RC_LIBDIR) + 1;
line = xmalloc (sizeof (char *) * i); line = xmalloc (sizeof (char) * i);
snprintf (line, i, "RC_LIBDIR=" RC_LIBDIR); snprintf (line, i, "RC_LIBDIR=" RC_LIBDIR);
rc_strlist_add (&env, line); rc_strlist_add (&env, line);
free (line); free (line);
/* One char less to drop the trailing / */ /* One char less to drop the trailing / */
i = strlen ("RC_SVCDIR=") + strlen (RC_SVCDIR) + 1; i = strlen ("RC_SVCDIR=") + strlen (RC_SVCDIR) + 1;
line = xmalloc (sizeof (char *) * i); line = xmalloc (sizeof (char) * i);
snprintf (line, i, "RC_SVCDIR=" RC_SVCDIR); snprintf (line, i, "RC_SVCDIR=" RC_SVCDIR);
rc_strlist_add (&env, line); rc_strlist_add (&env, line);
free (line); free (line);
@ -222,7 +222,7 @@ char **env_config (void)
rc_strlist_add (&env, "RC_BOOTLEVEL=" RC_LEVEL_BOOT); rc_strlist_add (&env, "RC_BOOTLEVEL=" RC_LEVEL_BOOT);
i = strlen ("RC_SOFTLEVEL=") + strlen (runlevel) + 1; i = strlen ("RC_SOFTLEVEL=") + strlen (runlevel) + 1;
line = xmalloc (sizeof (char *) * i); line = xmalloc (sizeof (char) * i);
snprintf (line, i, "RC_SOFTLEVEL=%s", runlevel); snprintf (line, i, "RC_SOFTLEVEL=%s", runlevel);
rc_strlist_add (&env, line); rc_strlist_add (&env, line);
free (line); free (line);
@ -234,7 +234,7 @@ char **env_config (void)
if (buffer[i] == '\n') if (buffer[i] == '\n')
buffer[i] = 0; buffer[i] = 0;
i += strlen ("RC_DEFAULTLEVEL=") + 2; i += strlen ("RC_DEFAULTLEVEL=") + 2;
line = xmalloc (sizeof (char *) * i); line = xmalloc (sizeof (char) * i);
snprintf (line, i, "RC_DEFAULTLEVEL=%s", buffer); snprintf (line, i, "RC_DEFAULTLEVEL=%s", buffer);
rc_strlist_add (&env, line); rc_strlist_add (&env, line);
free (line); free (line);
@ -267,7 +267,7 @@ char **env_config (void)
if (sys[0]) { if (sys[0]) {
i = strlen ("RC_SYS=") + strlen (sys) + 2; i = strlen ("RC_SYS=") + strlen (sys) + 2;
line = xmalloc (sizeof (char *) * i); line = xmalloc (sizeof (char) * i);
snprintf (line, i, "RC_SYS=%s", sys); snprintf (line, i, "RC_SYS=%s", sys);
rc_strlist_add (&env, line); rc_strlist_add (&env, line);
free (line); free (line);
@ -284,7 +284,7 @@ char **env_config (void)
if (! has_net_fs_list) { if (! has_net_fs_list) {
i = strlen ("RC_NET_FS_LIST=") + strlen (RC_NET_FS_LIST_DEFAULT) + 1; i = strlen ("RC_NET_FS_LIST=") + strlen (RC_NET_FS_LIST_DEFAULT) + 1;
line = xmalloc (sizeof (char *) * i); line = xmalloc (sizeof (char) * i);
snprintf (line, i, "RC_NET_FS_LIST=%s", RC_NET_FS_LIST_DEFAULT); snprintf (line, i, "RC_NET_FS_LIST=%s", RC_NET_FS_LIST_DEFAULT);
rc_strlist_add (&env, line); rc_strlist_add (&env, line);
free (line); free (line);
@ -294,7 +294,7 @@ char **env_config (void)
To save on calling uname, we store it in an environment variable */ To save on calling uname, we store it in an environment variable */
if (uname (&uts) == 0) { if (uname (&uts) == 0) {
i = strlen ("RC_UNAME=") + strlen (uts.sysname) + 2; i = strlen ("RC_UNAME=") + strlen (uts.sysname) + 2;
line = xmalloc (sizeof (char *) * i); line = xmalloc (sizeof (char) * i);
snprintf (line, i, "RC_UNAME=%s", uts.sysname); snprintf (line, i, "RC_UNAME=%s", uts.sysname);
rc_strlist_add (&env, line); rc_strlist_add (&env, line);
free (line); free (line);

View File

@ -1105,7 +1105,7 @@ int main (int argc, char **argv)
if ((dp = opendir ("/dev/net"))) { if ((dp = opendir ("/dev/net"))) {
while ((d = readdir (dp))) { while ((d = readdir (dp))) {
i = (strlen ("net.") + strlen (d->d_name) + 1); i = (strlen ("net.") + strlen (d->d_name) + 1);
tmp = xmalloc (sizeof (char *) * i); tmp = xmalloc (sizeof (char) * i);
snprintf (tmp, i, "net.%s", d->d_name); snprintf (tmp, i, "net.%s", d->d_name);
if (rc_service_exists (tmp) && if (rc_service_exists (tmp) &&
rc_service_plugable (tmp)) rc_service_plugable (tmp))
@ -1126,7 +1126,7 @@ int main (int argc, char **argv)
char *p = d->d_name + 3; char *p = d->d_name + 3;
if (p && isdigit (*p)) { if (p && isdigit (*p)) {
i = (strlen ("moused.") + strlen (d->d_name) + 1); i = (strlen ("moused.") + strlen (d->d_name) + 1);
tmp = xmalloc (sizeof (char *) * i); tmp = xmalloc (sizeof (char) * i);
snprintf (tmp, i, "moused.%s", d->d_name); snprintf (tmp, i, "moused.%s", d->d_name);
if (rc_service_exists (tmp) && rc_service_plugable (tmp)) if (rc_service_exists (tmp) && rc_service_plugable (tmp))
rc_service_mark (tmp, RC_SERVICE_COLDPLUGGED); rc_service_mark (tmp, RC_SERVICE_COLDPLUGGED);
@ -1246,7 +1246,7 @@ int main (int argc, char **argv)
continue; continue;
len = strlen (service) + strlen (runlevel) + 2; len = strlen (service) + strlen (runlevel) + 2;
tmp = xmalloc (sizeof (char *) * len); tmp = xmalloc (sizeof (char) * len);
snprintf (tmp, len, "%s.%s", service, runlevel); snprintf (tmp, len, "%s.%s", service, runlevel);
conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL); conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL);
found = exists (conf); found = exists (conf);
@ -1254,7 +1254,7 @@ int main (int argc, char **argv)
CHAR_FREE (tmp); CHAR_FREE (tmp);
if (! found) { if (! found) {
len = strlen (service) + strlen (newlevel) + 2; len = strlen (service) + strlen (newlevel) + 2;
tmp = xmalloc (sizeof (char *) * len); tmp = xmalloc (sizeof (char) * len);
snprintf (tmp, len, "%s.%s", service, newlevel); snprintf (tmp, len, "%s.%s", service, newlevel);
conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL); conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL);
found = exists (conf); found = exists (conf);

View File

@ -523,7 +523,7 @@ static void make_exclusive ()
path = rc_strcatpaths (RC_SVCDIR, "exclusive", applet, (char *) NULL); path = rc_strcatpaths (RC_SVCDIR, "exclusive", applet, (char *) NULL);
i = strlen (path) + 16; i = strlen (path) + 16;
mtime_test = xmalloc (sizeof (char *) * i); mtime_test = xmalloc (sizeof (char) * i);
snprintf (mtime_test, i, "%s.%d", path, getpid ()); snprintf (mtime_test, i, "%s.%d", path, getpid ());
free (path); free (path);
@ -730,7 +730,7 @@ static void svc_start (bool deps)
} }
len += 5; len += 5;
tmp = xmalloc (sizeof (char *) * len); tmp = xmalloc (sizeof (char) * len);
p = tmp; p = tmp;
STRLIST_FOREACH (tmplist, svc, i) { STRLIST_FOREACH (tmplist, svc, i) {
if (i > 1) { if (i > 1) {
@ -1117,7 +1117,7 @@ int runscript (int argc, char **argv)
} }
/* Make our prefix string */ /* Make our prefix string */
prefix = xmalloc (sizeof (char *) * l); prefix = xmalloc (sizeof (char) * l);
ll = strlen (applet); ll = strlen (applet);
memcpy (prefix, applet, ll); memcpy (prefix, applet, ll);
memset (prefix + ll, ' ', l - ll); memset (prefix + ll, ' ', l - ll);