|
From: <rg...@sd...> - 2003-10-16 18:59:23
|
This is a list of all files the differ from the cvs head and what is posted at http://rgr.freeshell.org/clucene/ in the clucene-8.1-withmemfixes-15Oct2003.tar.gz file: examples/demo/IndexFiles.cpp (on line 44 "delete buf" was changed to "delete[] buf") src/CLucene/analysis/AnalysisHeader.h (termText and type must deallocated with free() because they are allocated with stringDuplicate, which is the same as strdup() which uses malloc, on construction) src/CLucene/analysis/Analyzers.h The differences here may be unnecessary -- they consist of removing the const from the types of variables going into the VoidMap template, which is necessary if VoidMap is to call free() on those pointers, unless they are explicitly cast to void*. Probably a general avoidance of putting malloc'd memory into the VoidMap would be better. It's fine not to apply these changes if you can get things to compile without them, by using the casts or not sending malloc'd memory in so you can avoid the free()'s. src/CLucene/analysis/standard/StandardAnalyzer.cpp src/CLucene/analysis/standard/StandardAnalyzer.h Same as above. src/CLucene/document/Document.cpp src/CLucene/document/Document.h A simple type change in one function, just to make de-allocating something easier in the DocumentWriter.cpp and FieldInfos.cpp files below. src/CLucene/document/Field.cpp src/CLucene/document/Field.h Made a variable non-const, so that it could be free()'d, because it was allocated with stringDuplicate. Could have used a cast in the free call instead of changing the type. src/CLucene/index/DocumentWriter.cpp The variables "buf" and "rv" have to be delete[]'d not delete'd. Also, the elements of the list fields must be delete[]'d, see the change I did to Document.[h,cpp] above. src/CLucene/index/FieldInfo.h changed "delete name" to "free(name)" because it is allocated using stringDuplicate(). src/CLucene/index/FieldInfos.cpp See the Document.[h,cpp] changes -- this allowed me to avoid doing a "delete &var" and do a normal "delete var" instead. src/CLucene/index/FieldsReader.cpp buf must be delete[]'d, fvalue free()'d src/CLucene/index/FieldsWriter.cpp buf and rv must be delete[]'d, "delete &fields" changed to "delete fields" as per the Document.[h,cpp] changes. src/CLucene/index/IndexWriter.cpp mergedName must be delete[]'d. In newSegmentName() buf has to be allocated with new[], it can't just be on the stack, because it is allocated in other areas which means it will need to be delete[]'d. Instead of DocumentWriter& dw = *new DocumentWriter(); and then later delete &dw; I did DocumentWriter* dw = new DocumentWriter() and then later delete dw; and also changed a few dw.method() to dw->method accordingly. src/CLucene/index/SegmentInfo.h name was allocated with stringDuplicate, but is also declared const, so I changed "delete name" to "free( (void*) name);" src/CLucene/index/SegmentMerger.cpp buf and match must be delete[]'d, not delete'd. src/CLucene/index/SegmentReader.cpp segment must be free'd not deleted, and tmp must be delete[]'d not delete'd. The variable buf is sometimes static, sometimes new[]'d, and sometime stringDuplicated -- I got rid of the static one and handled the others appropriately, but it probably should be allocated via the same method everywhere. src/CLucene/index/SegmentTermDocs.cpp whitespace only src/CLucene/index/SegmentTermEnum.cpp buffer must be delete[]'d src/CLucene/index/Term.cpp field and text must be free'd not deleted src/CLucene/index/TermInfosReader.cpp src/CLucene/index/TermInfosWriter.cpp The variables n, indexTerms, indexPointers, indexInfos, and buf must all be delete[]'d. src/CLucene/search/FuzzyQuery.cpp whitespace only -- added newline at end of file (gcc complains) src/CLucene/store/FSDirectory.cpp src/CLucene/store/FSDirectory.h Changed type of fname to non-const so it could be free'd instead of deleted; could just as well cast it to void* before freeing. src/CLucene/store/InputStream.cpp src/CLucene/store/OutputStream.cpp Variables buffer and chars must be delete'd. src/CLucene/util/PriorityQueue.h variable heap must be delete[]'d src/CLucene/util/VoidMap.h Changed a delete to a free of itr->first. However, I think the correct fix here may be to make sure you always put ONLY new'd memory in this structure, and then to delete it. I think that VoidList.h has the same problem as VoidMap.h, in that sometimes the wrong kind of memory is put in there. To fix that we need to look carefully at how the code that uses those templates works. I plan to follow this up with a real patch file, and how to work through these changes line by line. I'll be sending another email in a few minutes. --Rob |