From 23c8426b42bb057c82a513c2f46c432a66feb75d Mon Sep 17 00:00:00 2001 From: Juergen Keil Date: Mon, 8 Oct 2001 18:06:34 +0000 Subject: *_get_dir broken for file lists with more than five entries due to bad malloc for mrl_t** double indirect mrl_t arrays. (old code was overwriting non-malloced memory) CVS patchset: 770 CVS date: 2001/10/08 18:06:34 --- src/input/input_file.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'src/input/input_file.c') diff --git a/src/input/input_file.c b/src/input/input_file.c index 128d2781e..f8be3e342 100644 --- a/src/input/input_file.c +++ b/src/input/input_file.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: input_file.c,v 1.24 2001/10/05 17:36:28 jkeil Exp $ + * $Id: input_file.c,v 1.25 2001/10/08 18:06:34 jkeil Exp $ */ #ifdef HAVE_CONFIG_H @@ -572,8 +572,9 @@ static mrl_t **file_plugin_get_dir (input_plugin_t *this_gen, */ for(i = 0; i < num_dir_files; i++) { - if(num_files >= this->mrls_allocated_entries - || this->mrls_allocated_entries == 0) { + if(num_files >= this->mrls_allocated_entries) { + ++this->mrls_allocated_entries; + this->mrls = realloc(this->mrls, (this->mrls_allocated_entries+1) * sizeof(mrl_t*)); this->mrls[num_files] = (mrl_t *) xmalloc(sizeof(mrl_t)); } else @@ -589,8 +590,9 @@ static mrl_t **file_plugin_get_dir (input_plugin_t *this_gen, */ for(i = 0; i < num_hide_files; i++) { - if(num_files >= this->mrls_allocated_entries - || this->mrls_allocated_entries == 0) { + if(num_files >= this->mrls_allocated_entries) { + ++this->mrls_allocated_entries; + this->mrls = realloc(this->mrls, (this->mrls_allocated_entries+1) * sizeof(mrl_t*)); this->mrls[num_files] = (mrl_t *) xmalloc(sizeof(mrl_t)); } else @@ -606,8 +608,9 @@ static mrl_t **file_plugin_get_dir (input_plugin_t *this_gen, */ for(i = 0; i < num_norm_files; i++) { - if(num_files >= this->mrls_allocated_entries - || this->mrls_allocated_entries == 0) { + if(num_files >= this->mrls_allocated_entries) { + ++this->mrls_allocated_entries; + this->mrls = realloc(this->mrls, (this->mrls_allocated_entries+1) * sizeof(mrl_t*)); this->mrls[num_files] = (mrl_t *) xmalloc(sizeof(mrl_t)); } else @@ -643,13 +646,9 @@ static mrl_t **file_plugin_get_dir (input_plugin_t *this_gen, /* * Freeing exceeded mrls if exists. */ - if(num_files > this->mrls_allocated_entries) - this->mrls_allocated_entries = num_files; - else if(this->mrls_allocated_entries > num_files) { - while(this->mrls_allocated_entries > num_files) { - MRL_ZERO(this->mrls[this->mrls_allocated_entries - 1]); - free(this->mrls[this->mrls_allocated_entries--]); - } + while(this->mrls_allocated_entries > num_files) { + MRL_ZERO(this->mrls[this->mrls_allocated_entries - 1]); + free(this->mrls[this->mrls_allocated_entries--]); } /* @@ -777,7 +776,7 @@ input_plugin_t *init_input_plugin (int iface, config_values_t *config) { this->mrl = NULL; this->config = config; - this->mrls = (mrl_t **) xmalloc(sizeof(mrl_t)); + this->mrls = (mrl_t **) xmalloc(sizeof(mrl_t*)); this->mrls_allocated_entries = 0; return (input_plugin_t *) this; -- cgit v1.2.3