diff options
author | ben <benjaminfranzke@googlemail.com> | 2010-07-13 00:24:21 +0200 |
---|---|---|
committer | ben <benjaminfranzke@googlemail.com> | 2010-07-13 00:24:21 +0200 |
commit | f2b8a7000aef9b7eecc0396d9bbe0ccfee9b8100 (patch) | |
tree | b9fac9471524c828ee0816348c3c38922bd3eacc | |
parent | 6c2431b9f428d21b5219be97d07c7ce580a30983 (diff) | |
download | pa-sink-ctl-f2b8a7000aef9b7eecc0396d9bbe0ccfee9b8100.tar.gz pa-sink-ctl-f2b8a7000aef9b7eecc0396d9bbe0ccfee9b8100.tar.bz2 pa-sink-ctl-f2b8a7000aef9b7eecc0396d9bbe0ccfee9b8100.zip |
fix reallocs that saved pointer only in local vars
-rw-r--r-- | src/pa-sink-ctl.c | 2 | ||||
-rw-r--r-- | src/sink.c | 18 | ||||
-rw-r--r-- | src/sink.h | 2 | ||||
-rw-r--r-- | src/sink_input.c | 12 | ||||
-rw-r--r-- | src/sink_input.h | 2 |
5 files changed, 19 insertions, 17 deletions
diff --git a/src/pa-sink-ctl.c b/src/pa-sink-ctl.c index b841535..42ebc07 100644 --- a/src/pa-sink-ctl.c +++ b/src/pa-sink-ctl.c @@ -107,7 +107,7 @@ void get_sink_info_callback(pa_context *c, const pa_sink_info *i, int is_last, v return; } - sink_list_check(sink_list, &sink_max, sink_counter); + sink_list_check(&sink_list, &sink_max, sink_counter); sink_check(&(sink_list[sink_counter])); sink_list[sink_counter]->index = i->index; sink_list[sink_counter]->mute = i->mute; @@ -50,21 +50,23 @@ void sink_check(sink_info** sink) { /* * check the list length and resize the list, if current position = max */ -void sink_list_check(sink_info** sink_list, uint32_t* max, uint32_t counter) { +void sink_list_check(sink_info*** sink_list, uint32_t* max, uint32_t counter) { + if (counter < *max) + return; - if (counter >= (*max)) { - (*max) *= 2; - sink_list = (sink_info**) realloc(sink_list, (*max) * sizeof(sink_info*)); + *max *= 2; + *sink_list = (sink_info**) realloc(*sink_list, (*max) * sizeof(sink_info*)); + + + for (int i = counter; i < *max; ++i) + (*sink_list)[i] = NULL; - for (int i = counter; i < (*max); ++i) - sink_list[i] = NULL; - } } void sink_check_input_list(sink_info* sink) { if (sink->input_counter >= sink->input_max) - sink_input_list_enlarge(sink->input_list, &sink->input_max, sink->input_counter); + sink_input_list_enlarge(&sink->input_list, &sink->input_max, sink->input_counter); } sink_info** sink_list_init(uint32_t max) { @@ -25,7 +25,7 @@ sink_info* sink_init(void); void sink_clear(sink_info*); void sink_check(sink_info**); -void sink_list_check(sink_info**, uint32_t*, uint32_t); +void sink_list_check(sink_info***, uint32_t*, uint32_t); void sink_check_input_list(sink_info*); sink_info** sink_list_init(uint32_t); diff --git a/src/sink_input.c b/src/sink_input.c index 0940a4b..9a72899 100644 --- a/src/sink_input.c +++ b/src/sink_input.c @@ -27,7 +27,7 @@ void sink_input_clear(sink_input_info* sink_input) { sink_input = NULL; } -sink_input_info** sink_input_list_init(int max) { +sink_input_info** sink_input_list_init(int max) { sink_input_info** sink_input_list = (sink_input_info**) calloc(max, sizeof(sink_input_info*)); @@ -37,13 +37,13 @@ sink_input_info** sink_input_list_init(int max) { return sink_input_list; } -void sink_input_list_enlarge(sink_input_info** sink_input_list, int* max, int counter) { +void sink_input_list_enlarge(sink_input_info*** sink_input_list, int* max, int counter) { - (*max) *= 2; - sink_input_list = (sink_input_info**) realloc(sink_input_list, (*max) * sizeof(sink_input_info*)); + *max *= 2; + *sink_input_list = (sink_input_info**) realloc(*sink_input_list, (*max) * sizeof(sink_input_info*)); - for (int i = counter; i < (*max); ++i) - sink_input_list[i] = NULL; + for (int i = counter; i < *max; ++i) + (*sink_input_list)[i] = NULL; } void sink_input_list_clear(sink_input_info** sink_input_list, int *max) { diff --git a/src/sink_input.h b/src/sink_input.h index f6fa1ac..92ff4bb 100644 --- a/src/sink_input.h +++ b/src/sink_input.h @@ -17,7 +17,7 @@ sink_input_info* sink_input_init(void); void sink_input_clear(sink_input_info*); sink_input_info** sink_input_list_init(int); -void sink_input_list_enlarge(sink_input_info**, int*, int); +void sink_input_list_enlarge(sink_input_info***, int*, int); void sink_input_list_clear(sink_input_info**, int*); void sink_input_check(sink_input_info**); int cmp_sink_input_list(const void *, const void *); |