From b3f39211b20bae9ddf28cacb3d3278aba0e2a3de Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Tue, 30 Jun 2009 20:47:53 +0000 Subject: [PATCH] Consolidate strdup calls in sensors_get_label (patch from George Spelvin). There were multiple in-line calls that then fell through to a common exit. Instead, set up a pointer to the original strings, and have a single strdup in the common code. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@5747 7894878c-1315-0410-8ee3-d5d059ff63e0 --- lib/access.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/access.c b/lib/access.c index 01c345ea..d231dffb 100644 --- a/lib/access.c +++ b/lib/access.c @@ -178,7 +178,7 @@ char *sensors_get_label(const sensors_chip_name *name, for (chip = NULL; (chip = sensors_for_all_config_chips(name, chip));) for (i = 0; i < chip->labels_count; i++) if (!strcmp(feature->name, chip->labels[i].name)) { - label = strdup(chip->labels[i].value); + label = chip->labels[i].value; goto sensors_get_label_exit; } @@ -191,15 +191,16 @@ char *sensors_get_label(const sensors_chip_name *name, if (i > 0) { /* i - 1 to strip the '\n' at the end */ buf[i - 1] = 0; - label = strdup(buf); + label = buf; goto sensors_get_label_exit; } } /* No label, return the feature name instead */ - label = strdup(feature->name); + label = feature->name; sensors_get_label_exit: + label = strdup(label); if (!label) sensors_fatal_error(__func__, "Allocating label text"); return label;