Update of /cvsroot/mahogany/M/src/classes
In directory usw-pr-cvs1:/tmp/cvs-serv16558/src/classes
Modified Files:
MessageView.cpp
Log Message:
fixed memory leaks when calling wxGetTempFileName
Index: MessageView.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/classes/MessageView.cpp,v
retrieving revision 1.88
retrieving revision 1.89
diff -b -u -2 -r1.88 -r1.89
--- MessageView.cpp 3 May 2002 19:06:42 -0000 1.88
+++ MessageView.cpp 13 May 2002 23:32:56 -0000 1.89
@@ -2097,5 +2097,7 @@
#else // 1
bool ok = false;
- char *filename = wxGetTempFileName("Mtemp");
+ wxString filename;
+ if ( wxGetTempFileName("Mtemp", filename) )
+ {
if ( MimeSave(mimepart, filename) )
{
@@ -2116,6 +2118,6 @@
if ( asmf )
{
- // FIXME: assume UID of the first message in a new MBX folder is
- // always 1
+ // FIXME: assume UID of the first message in a new MBX folder
+ // is always 1
ShowMessageViewFrame(GetParentFrame(), asmf, 1);
@@ -2127,9 +2129,10 @@
else
{
- // note that if we succeeded with folder creation, it will delete
- // the file itself (because of MF_FLAGS_TEMPORARY)
+ // note that if we succeeded with folder creation, it will
+ // delete the file itself (because of MF_FLAGS_TEMPORARY)
wxRemoveFile(filename);
}
}
+ }
if ( !ok )
@@ -2142,12 +2145,18 @@
}
- String
- filename = wxGetTempFileName("Mtemp"),
- filename2 = "";
+ String filename;
+ if ( !wxGetTempFileName("Mtemp", filename) )
+ {
+ wxLogError(_("Failed to open the attachment."));
+
+ delete fileType;
+ return;
+ }
wxString ext;
wxSplitPath(filenameOrig, NULL, NULL, &ext);
+
// get the standard extension for such files if there is no real one
- if ( fileType != NULL && !ext)
+ if ( fileType != NULL && ext.empty() )
{
wxArrayString exts;
@@ -2178,6 +2187,6 @@
MailMessageParameters params(filename, mimetype, mimepart);
- // We might fake a file, so we need this:
- bool already_saved = false;
+ // have we already saved the file to disk?
+ bool saved = false;
Profile *profile = GetProfile();
@@ -2217,8 +2226,8 @@
// use TIFF2PS command to create a postscript file, open that
// one with the usual ps viewer
- filename2 = filename.BeforeLast('.') + ".ps";
+ String filenamePS = filename.BeforeLast('.') + ".ps";
String command;
command.Printf(READ_CONFIG_TEXT(profile,MP_TIFF2PS),
- filename.c_str(), filename2.c_str());
+ filename.c_str(), filenamePS.c_str());
// we ignore the return code, because next viewer will fail
// or succeed depending on this:
@@ -2232,5 +2241,5 @@
wxRemoveFile(filename);
- filename = filename2;
+ filename = filenamePS;
mimetype = "application/postscript";
if(fileType) delete fileType;
@@ -2240,5 +2249,5 @@
MailMessageParameters new_params(filename, mimetype, mimepart);
params = new_params;
- already_saved = true; // use this file instead!
+ saved = true; // use this file instead!
}
}
@@ -2246,9 +2255,17 @@
// We must save the file before actually calling GetOpenCommand()
- if( !already_saved )
+ if( !saved )
{
- MimeSave(mimepart, filename);
- already_saved = TRUE;
+ if ( !MimeSave(mimepart, filename) )
+ {
+ wxLogError(_("Failed to open the attachment."));
+
+ delete fileType;
+ return;
+ }
+
+ saved = TRUE;
}
+
String command;
if ( (fileType == NULL) || !fileType->GetOpenCommand(&command, params) )
@@ -2288,10 +2305,7 @@
}
- if ( fileType )
delete fileType;
- if ( ! command.empty() )
- {
- if(already_saved || MimeSave(mimepart, filename))
+ if ( !command.empty() )
{
wxString errmsg;
@@ -2300,5 +2314,4 @@
(void)LaunchProcess(command, errmsg, filename);
}
- }
}
_______________________________________________________________
Have big pipes? SourceForge.net is looking for download mirrors. We supply
the hardware. You get the recognition. Email Us: [EMAIL PROTECTED]
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates