From f2b8a7000aef9b7eecc0396d9bbe0ccfee9b8100 Mon Sep 17 00:00:00 2001 From: ben Date: Tue, 13 Jul 2010 00:24:21 +0200 Subject: fix reallocs that saved pointer only in local vars --- src/pa-sink-ctl.c | 2 +- src/sink.c | 18 ++++++++++-------- src/sink.h | 2 +- src/sink_input.c | 12 ++++++------ 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; diff --git a/src/sink.c b/src/sink.c index 38f061b..3622f74 100644 --- a/src/sink.c +++ b/src/sink.c @@ -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) { diff --git a/src/sink.h b/src/sink.h index 78f5837..03c557f 100644 --- a/src/sink.h +++ b/src/sink.h @@ -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 *); -- cgit