SHA256
1
0
forked from pool/alsa-utils
alsa-utils/0014-alsatplg-add-s-sort-and-fix-memory-leaks.patch
Takashi Iwai 7200ea9d85 Accepting request 766332 from home:tiwai:branches:multimedia:libs
- Backport upstream patches:
  A few portability fixes, alsaucm fixes and extensions, alsatplg
  minor fixes, alsa-info.sh extensions:
  0001-treewide-sys-poll-to-poll.patch
  0002-treewide-Fix-wrong-formats-on-32-bit.patch
  0003-treewide-Fix-printf-formats.patch
  0004-aplay-Adjust-buffer-sizes-to-fix-snprintf-warnings.patch
  0005-aplay-Limit-VUMeter-progress-bar-to-100-for-negative.patch
  0006-alsactl-sysfs-add-sys-kernel-uevent_seqnum-check-to-.patch
  0007-alsaucm-use-the-first-sound-card-use-case-name-hw-CA.patch
  0008-alsaucm-add-text-dump-command.patch
  0009-alsaucm-add-json-dump-command.patch
  0010-alsaucm-dump-fix-the-prefixed.patch
  0011-alsactl-fix-sched-idle-set-it-really-to-SCHED_IDLE.patch
  0012-configure-Fix-linking-of-alsatplg-with-the-older-lib.patch
  0013-alsatplg-add-n-normalize-option.patch
  0014-alsatplg-add-s-sort-and-fix-memory-leaks.patch
  0015-alsatplg-fix-another-small-leak-in-normalize_config.patch
  0016-alsa-info.sh-Consolidate-PCI-device-output.patch
  0017-alsa-info.sh-Read-from-proc-modules-and-sort-the-res.patch
  0018-alsa-info.sh-Simplify-iteration-over-cards-when-call.patch
  0019-alsa-info.sh-Use-existing-function-to-print-ALSA-con.patch
  0020-alsa-info.sh-Exit-script-after-writing-information-t.patch
  0021-alsa-info.sh-Replace-gauge-with-infobox-for-upload-d.patch
  0022-alsa-info.sh-Remove-progress-spinner-during-upload-w.patch
  0023-alsa-info.sh-Condense-nested-commands-for-file-uploa.patch
  0024-alsa-info.sh-Condense-nested-commands-for-formatting.patch
  0025-alsa-info.sh-Perform-test-for-wget-earlier.patch
  0026-alsa-info.sh-Warn-after-actual-upload-failure-do-not.patch

OBS-URL: https://build.opensuse.org/request/show/766332
OBS-URL: https://build.opensuse.org/package/show/multimedia:libs/alsa-utils?expand=0&rev=165
2020-01-22 14:28:06 +00:00

142 lines
4.2 KiB
Diff

From 2656d4bec8fab8b4b9046d3b8c9c255dc2166014 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <perex@perex.cz>
Date: Thu, 12 Dec 2019 19:18:28 +0100
Subject: [PATCH 14/26] alsatplg: add -s,--sort and fix memory leaks
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
topology/topology.c | 34 ++++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/topology/topology.c b/topology/topology.c
index a6ebafab161b..c12be7806929 100644
--- a/topology/topology.c
+++ b/topology/topology.c
@@ -46,6 +46,7 @@ _("Usage: %s [OPTIONS]...\n"
"-n, --normalize=FILE normalize file\n"
"-v, --verbose=LEVEL set verbosity level (0...1)\n"
"-o, --output=FILE set output file\n"
+"-s, --sort sort the identifiers in the normalized output\n"
), name);
}
@@ -59,7 +60,7 @@ static int _compar(const void *a, const void *b)
return strcmp(id1, id2);
}
-static snd_config_t *normalize_config(const char *id, snd_config_t *src)
+static snd_config_t *normalize_config(const char *id, snd_config_t *src, int sort)
{
snd_config_t *dst, **a;
snd_config_iterator_t i, next;
@@ -70,8 +71,6 @@ static snd_config_t *normalize_config(const char *id, snd_config_t *src)
return dst;
return NULL;
}
- if (snd_config_make_compound(&dst, id, 0))
- return NULL;
count = 0;
snd_config_for_each(i, next, src)
count++;
@@ -83,20 +82,28 @@ static snd_config_t *normalize_config(const char *id, snd_config_t *src)
snd_config_t *s = snd_config_iterator_entry(i);
a[index++] = s;
}
- qsort(a, count, sizeof(a[0]), _compar);
+ if (sort)
+ qsort(a, count, sizeof(a[0]), _compar);
+ if (snd_config_make_compound(&dst, id, count == 1)) {
+ free(a);
+ return NULL;
+ }
for (index = 0; index < count; index++) {
snd_config_t *s = a[index];
const char *id2;
if (snd_config_get_id(s, &id2)) {
snd_config_delete(dst);
+ free(a);
return NULL;
}
- s = normalize_config(id2, s);
+ s = normalize_config(id2, s, sort);
if (s == NULL || snd_config_add(dst, s)) {
snd_config_delete(dst);
+ free(a);
return NULL;
}
}
+ free(a);
return dst;
}
@@ -125,7 +132,7 @@ static int compile(const char *source_file, const char *output_file, int verbose
return 1;
}
-static int normalize(const char *source_file, const char *output_file)
+static int normalize(const char *source_file, const char *output_file, int sort)
{
snd_input_t *input;
snd_output_t *output;
@@ -160,7 +167,7 @@ static int normalize(const char *source_file, const char *output_file)
return 1;
}
- norm = normalize_config(NULL, top);
+ norm = normalize_config(NULL, top, sort);
if (norm == NULL) {
fprintf(stderr, "Unable to normalize configuration (out of memory?)\n");
snd_output_close(output);
@@ -170,6 +177,7 @@ static int normalize(const char *source_file, const char *output_file)
err = snd_config_save(norm, output);
snd_output_close(output);
+ snd_config_delete(norm);
snd_config_delete(top);
if (err < 0) {
fprintf(stderr, "Unable to save normalized contents: %s\n", snd_strerror(-err));
@@ -181,17 +189,18 @@ static int normalize(const char *source_file, const char *output_file)
int main(int argc, char *argv[])
{
- static const char short_options[] = "hc:n:v:o:";
+ static const char short_options[] = "hc:n:v:o:s";
static const struct option long_options[] = {
{"help", 0, NULL, 'h'},
{"verbose", 1, NULL, 'v'},
{"compile", 1, NULL, 'c'},
{"normalize", 1, NULL, 'n'},
{"output", 1, NULL, 'o'},
+ {"sort", 0, NULL, 's'},
{0, 0, 0, 0},
};
char *source_file = NULL, *normalize_file = NULL, *output_file = NULL;
- int c, err, verbose = 0, option_index;
+ int c, err, verbose = 0, sort = 0, option_index;
#ifdef ENABLE_NLS
setlocale(LC_ALL, "");
@@ -218,6 +227,9 @@ int main(int argc, char *argv[])
case 'o':
output_file = optarg;
break;
+ case 's':
+ sort = 1;
+ break;
default:
fprintf(stderr, _("Try `%s --help' for more information.\n"), argv[0]);
return 1;
@@ -237,6 +249,8 @@ int main(int argc, char *argv[])
if (source_file)
err = compile(source_file, output_file, verbose);
else
- err = normalize(normalize_file, output_file);
+ err = normalize(normalize_file, output_file, sort);
+
+ snd_output_close(log);
return 0;
}
--
2.16.4