Skip to content

Commit

Permalink
Merge pull request lithiumFlower#4 from lithiumFlower/fix-memory-leak
Browse files Browse the repository at this point in the history
Fix memory leak
  • Loading branch information
lithiumFlower authored Jul 16, 2020
2 parents a375584 + 356aee8 commit 56570c0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ Ensure the following are installed and in the path:
The most recent compilation was done in a git-bash shell using mingw64

#### Mac
Building on Mac will take some extra work. My initial attempt was not an "all in a days work" task. It appears that the 3rdparty libraries like wv2 are compiled against libstdc++. The standard on OSX is now libc++. I no longer have the requisite headers available on my machine to compile against libstdc++ - as of Xcode 10 this support was dropped. This leads to:
1. Udating the 3rdparty libraries. Most of them shouldn't be so bad but wv2 will be a bit more of a lift. Normally wv2 requires gsf which in turn requires glib, however SILVERCODERS has patched their ancient version (0.2.3) to no longer rely on gsf+glib. Additionally it takes different interface (the custom ThreadSafeOLEStorage class instead opposed to buffers and strings). In order to preserve the distributable nature of the package gsf and glib will need to be repackaged along with a modern version of wv2. The new classes of wv2 (OLEStorage, OLEStreamReader, over AbstractOLEStorage, AbstractOLEStreamReader) will need to be used. And finally, the new classes cause other glib/gsf dependent changes, such as stream changes for compatibility with GsfInput. I hope I've missed a simpler alternative.
2. Finding an alternative sustainable means of compiling against libstdc++ on OSX


#### Linux
TODO


### What is DocToText
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0.0
5.0.1
29 changes: 25 additions & 4 deletions src/thread_safe_ole_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ struct ThreadSafeOLEStorage::Implementation
{
if (m_data_stream)
delete m_data_stream;

// m_child_directories and m_inside_directories are all duplicate pointers of entries in
// m_directories so no need to delete those
for (DirectoryEntry *d : m_directories) {
delete d;
}
}

void getStreamPositions(std::vector<uint32_t>& stream_positions, bool mini_stream, DirectoryEntry* dir_entry)
Expand Down Expand Up @@ -267,13 +273,15 @@ struct ThreadSafeOLEStorage::Implementation
try
{
directory = NULL;
// TODO: update to managed pointers
directory = new DirectoryEntry;
directory->m_added = false;
uint16_t unichars[32];
if (!m_data_stream->read(unichars, sizeof(uint16_t), 32))
{
m_error = "Error in reading directory name";
m_is_valid_ole = false;
delete directory;
return;
}
for (int j = 0; j < 32; ++j)
Expand All @@ -290,19 +298,23 @@ struct ThreadSafeOLEStorage::Implementation
}
directory->m_name += unichar_to_utf8(ch);
}
if (!skipBytes(2))
return;
if (!skipBytes(2)) {
delete directory;
return;
}
uint8_t object_type;
if (!m_data_stream->read(&object_type, sizeof(uint8_t), 1))
{
m_error = "Error in reading type of object";
m_is_valid_ole = false;
delete directory;
return;
}
if (object_type != 0x00 && object_type != 0x01 && object_type != 0x02 && object_type != 0x05)
{
m_error = "Invalid type of object";
m_is_valid_ole = false;
delete directory;
return;
}
directory->m_object_type = (DirectoryEntry::ObjectType)object_type;
Expand All @@ -311,45 +323,54 @@ struct ThreadSafeOLEStorage::Implementation
{
m_error = "Error in reading color flag";
m_is_valid_ole = false;
delete directory;
return;
}
if (color_flag != 0x00 && color_flag != 0x01)
{
m_error = "Invalid color flag";
m_is_valid_ole = false;
delete directory;
return;
}
directory->m_color_flag = color_flag;
if (!m_data_stream->read(&directory->m_left_sibling, sizeof(uint32_t), 1))
{
m_error = "Error in reading left sibling";
m_is_valid_ole = false;
delete directory;
return;
}
if (!m_data_stream->read(&directory->m_right_sibling, sizeof(uint32_t), 1))
{
m_error = "Error in reading directory right sibling";
m_is_valid_ole = false;
delete directory;
return;
}
if (!m_data_stream->read(&directory->m_child, sizeof(uint32_t), 1))
{
m_error = "Error in reading child";
m_is_valid_ole = false;
delete directory;
return;
}
if (!skipBytes(36))
return;
if (!skipBytes(36)) {
delete directory;
return;
}
if (!m_data_stream->read(&directory->m_start_sector_location, sizeof(uint32_t), 1))
{
m_error = "Error in reading sector location";
m_is_valid_ole = false;
delete directory;
return;
}
if (!m_data_stream->read(&directory->m_stream_size, sizeof(uint64_t), 1))
{
m_error = "Error in reading sector size";
m_is_valid_ole = false;
delete directory;
return;
}
if (m_header_version == 0x03)
Expand Down

0 comments on commit 56570c0

Please sign in to comment.