mirror of https://github.com/OpenTTD/OpenTTD
(svn r13810) -Fix: small memory leak when tar files would be found.
parent
a050a78525
commit
81c50c6c32
|
@ -337,7 +337,7 @@ FILE *FioFOpenFileSp(const char *filename, const char *mode, Searchpath sp, Subd
|
||||||
|
|
||||||
FILE *FioFOpenFileTar(TarFileListEntry *entry, size_t *filesize)
|
FILE *FioFOpenFileTar(TarFileListEntry *entry, size_t *filesize)
|
||||||
{
|
{
|
||||||
FILE *f = fopen(entry->tar->filename, "rb");
|
FILE *f = fopen(entry->tar_filename, "rb");
|
||||||
assert(f != NULL);
|
assert(f != NULL);
|
||||||
|
|
||||||
fseek(f, entry->position, SEEK_SET);
|
fseek(f, entry->position, SEEK_SET);
|
||||||
|
@ -513,9 +513,8 @@ static bool TarListAddFile(const char *filename)
|
||||||
FILE *f = fopen(filename, "rb");
|
FILE *f = fopen(filename, "rb");
|
||||||
assert(f != NULL);
|
assert(f != NULL);
|
||||||
|
|
||||||
TarListEntry *tar_entry = MallocT<TarListEntry>(1);
|
const char *dupped_filename = strdup(filename);
|
||||||
tar_entry->filename = strdup(filename);
|
_tar_list[filename].filename = dupped_filename;
|
||||||
_tar_list.insert(TarList::value_type(filename, tar_entry));
|
|
||||||
|
|
||||||
TarLinkList links; ///< Temporary list to collect links
|
TarLinkList links; ///< Temporary list to collect links
|
||||||
|
|
||||||
|
@ -575,9 +574,9 @@ static bool TarListAddFile(const char *filename)
|
||||||
|
|
||||||
/* Store this entry in the list */
|
/* Store this entry in the list */
|
||||||
TarFileListEntry entry;
|
TarFileListEntry entry;
|
||||||
entry.tar = tar_entry;
|
entry.tar_filename = dupped_filename;
|
||||||
entry.size = skip;
|
entry.size = skip;
|
||||||
entry.position = pos;
|
entry.position = pos;
|
||||||
|
|
||||||
/* Convert to lowercase and our PATHSEPCHAR */
|
/* Convert to lowercase and our PATHSEPCHAR */
|
||||||
SimplifyFileName(name);
|
SimplifyFileName(name);
|
||||||
|
|
|
@ -11,15 +11,17 @@
|
||||||
/** The define of a TarList. */
|
/** The define of a TarList. */
|
||||||
struct TarListEntry {
|
struct TarListEntry {
|
||||||
const char *filename;
|
const char *filename;
|
||||||
|
|
||||||
|
~TarListEntry() { free((void*)this->filename); }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TarFileListEntry {
|
struct TarFileListEntry {
|
||||||
TarListEntry *tar;
|
const char *tar_filename;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t position;
|
size_t position;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::map<std::string, TarListEntry *> TarList;
|
typedef std::map<std::string, TarListEntry> TarList;
|
||||||
typedef std::map<std::string, TarFileListEntry> TarFileList;
|
typedef std::map<std::string, TarFileListEntry> TarFileList;
|
||||||
extern TarList _tar_list;
|
extern TarList _tar_list;
|
||||||
extern TarFileList _tar_filelist;
|
extern TarFileList _tar_filelist;
|
||||||
|
|
Loading…
Reference in New Issue