From 2bc524f35862de3a8ffd3793d815ad6ec9d9ff06 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Sun, 24 Mar 2002 15:50:57 +0000 Subject: [PATCH] dirty fix for even dirtier memory leak git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14762 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/html/virtual/virtual.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/samples/html/virtual/virtual.cpp b/samples/html/virtual/virtual.cpp index 8672b7b277..a34298dc02 100644 --- a/samples/html/virtual/virtual.cpp +++ b/samples/html/virtual/virtual.cpp @@ -54,7 +54,7 @@ wxFSFile* MyVFS::OpenFile(wxFileSystem& fs, const wxString& location) { wxFSFile *f; wxInputStream *str; - char *buf = (char*)malloc(1024); + static char buf[1024]; sprintf(buf, "

You're in Node %s

" "Where do you want to go?

" @@ -64,10 +64,14 @@ wxFSFile* MyVFS::OpenFile(wxFileSystem& fs, const wxString& location) "
", location.GetData(), location.GetData(), location.GetData(), location.GetData()); - // WARNING: wxMemoryInputStream will not free buf. - // There is a memory leak here. + // NB: There's a terrible hack involved: we fill 'buf' with new data every + // time this method is called and return new wxMemoryInputStream pointing to it. + // This won't work as soon as there are 2+ myVFS files opened. Fortunately, + // this won't happen because wxHTML keeps only one "page" file opened at the + // time. str = new wxMemoryInputStream(buf, strlen(buf)); f = new wxFSFile(str, location, "text/html", wxEmptyString, wxDateTime::Today()); + return f; } -- 2.47.2