remove superfluous strdup() calls

Remove same calls of strdup() that were unnecessary because the
temporary string would not be modified or held longer than the lifetime
of the original string.
This commit is contained in:
Clemens Ladisch 2007-02-12 13:45:03 +01:00
parent ebc0ea9b54
commit 0c49463b8c

View file

@ -227,7 +227,8 @@ int snd_func_getenv(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
{ {
snd_config_t *n, *d; snd_config_t *n, *d;
snd_config_iterator_t i, next; snd_config_iterator_t i, next;
char *res, *def = NULL; const char *res, *id;
char *def = NULL;
int idx = 0, err, hit; int idx = 0, err, hit;
err = snd_config_search(src, "vars", &n); err = snd_config_search(src, "vars", &n);
@ -259,7 +260,7 @@ int snd_func_getenv(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
hit = 0; hit = 0;
snd_config_for_each(i, next, n) { snd_config_for_each(i, next, n) {
snd_config_t *n = snd_config_iterator_entry(i); snd_config_t *n = snd_config_iterator_entry(i);
const char *id, *ptr, *env; const char *ptr;
long i; long i;
if (snd_config_get_id(n, &id) < 0) if (snd_config_get_id(n, &id) < 0)
continue; continue;
@ -282,26 +283,18 @@ int snd_func_getenv(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
err = -EINVAL; err = -EINVAL;
goto __error; goto __error;
} }
env = getenv(ptr); res = getenv(ptr);
if (env != NULL && *env != '\0') { if (res != NULL && *res != '\0')
res = strdup(env);
goto __ok; goto __ok;
}
hit = 1; hit = 1;
} }
} }
} while (hit); } while (hit);
res = def; res = def;
def = NULL;
__ok: __ok:
err = res == NULL ? -ENOMEM : 0; err = snd_config_get_id(src, &id);
if (err >= 0) { if (err >= 0)
const char *id; err = snd_config_imake_string(dst, id, res);
err = snd_config_get_id(src, &id);
if (err >= 0)
err = snd_config_imake_string(dst, id, res);
free(res);
}
__error: __error:
free(def); free(def);
return err; return err;
@ -869,7 +862,6 @@ SND_DLSYM_BUILD_VERSION(snd_func_card_driver, SND_CONFIG_DLSYM_VERSION_EVALUATE)
int snd_func_card_id(snd_config_t **dst, snd_config_t *root, snd_config_t *src, int snd_func_card_id(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
snd_config_t *private_data) snd_config_t *private_data)
{ {
char *res = NULL;
snd_ctl_t *ctl = NULL; snd_ctl_t *ctl = NULL;
snd_ctl_card_info_t *info; snd_ctl_card_info_t *info;
const char *id; const char *id;
@ -889,15 +881,10 @@ int snd_func_card_id(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
SNDERR("snd_ctl_card_info error: %s", snd_strerror(err)); SNDERR("snd_ctl_card_info error: %s", snd_strerror(err));
goto __error; goto __error;
} }
res = strdup(snd_ctl_card_info_get_id(info));
if (res == NULL) {
err = -ENOMEM;
goto __error;
}
err = snd_config_get_id(src, &id); err = snd_config_get_id(src, &id);
if (err >= 0) if (err >= 0)
err = snd_config_imake_string(dst, id, res); err = snd_config_imake_string(dst, id,
free(res); snd_ctl_card_info_get_id(info));
__error: __error:
if (ctl) if (ctl)
snd_ctl_close(ctl); snd_ctl_close(ctl);
@ -1148,11 +1135,9 @@ int snd_func_pcm_args_by_class(snd_config_t **dst, snd_config_t *root, snd_confi
if (err < 0) if (err < 0)
return err; return err;
if((err = snd_config_get_id(src, &id)) >= 0) { if((err = snd_config_get_id(src, &id)) >= 0) {
char name[32], *s; char name[32];
snprintf(name, sizeof(name), "CARD=%i,DEV=%i", card, dev); snprintf(name, sizeof(name), "CARD=%i,DEV=%i", card, dev);
if (!(s = strdup(name))) err = snd_config_imake_string(dst, id, name);
return -ENOMEM;
err = snd_config_imake_string(dst, id, s);
} }
return err; return err;
} }