From eca977e618f2d4c6d55d9851b9714fd60e55559b Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 7 May 2006 05:48:06 +0000 Subject: [PATCH] Fix memory leak in scratch reader. --- src/data/ChangeLog | 7 +++++++ src/data/scratch-reader.c | 21 ++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/data/ChangeLog b/src/data/ChangeLog index e323b22d..a6e6b004 100644 --- a/src/data/ChangeLog +++ b/src/data/ChangeLog @@ -1,3 +1,10 @@ +Sat May 6 22:46:47 2006 Ben Pfaff + + * scratch-reader.c (scratch_reader_read_case): Copy into existing + case passed as argument instead of initializing the argument as a + case. Fixes memory leak that showed up in + tests/command/aggregate.sh with scratch files. + Sat May 6 22:45:55 2006 Ben Pfaff * procedure.c (proc_done): Destroy default_dict, to fix memory diff --git a/src/data/scratch-reader.c b/src/data/scratch-reader.c index e329d1c8..cb94e245 100644 --- a/src/data/scratch-reader.c +++ b/src/data/scratch-reader.c @@ -18,13 +18,18 @@ 02110-1301, USA. */ #include + #include "scratch-reader.h" + #include + #include "casefile.h" #include "dictionary.h" -#include #include "file-handle-def.h" #include "scratch-handle.h" +#include +#include + #include "xalloc.h" #include "gettext.h" @@ -70,12 +75,22 @@ scratch_reader_open (struct file_handle *fh, struct dictionary **dict) return reader; } -/* Reads a case from READER into C. +/* Reads a case from READER and copies it into C. Returns true if successful, false on error or at end of file. */ bool scratch_reader_read_case (struct scratch_reader *reader, struct ccase *c) { - return casereader_read (reader->casereader, c); + struct ccase tmp; + if (casereader_read (reader->casereader, &tmp)) + { + case_copy (c, 0, &tmp, 0, + casefile_get_value_cnt ( + casereader_get_casefile (reader->casereader))); + case_destroy (&tmp); + return true; + } + else + return false; } /* Returns true if an I/O error occurred on READER, false otherwise. */ -- 2.30.2