Discussion:
D5 to D2007 FreeMem(pDriver, MAS_PATH)
(too old to reply)
Anthony Nasca
2008-03-15 04:37:53 UTC
Permalink
GetMem(pDevice, cchDeviceName);
GetMem(pDriver, MAX_PATH);
GetMem(pPort, MAX_PATH);
GetProfileString('Devices', pchar(scboPrinter), '', pDriver,
MAX_PATH);
pDriver[pos(',', pDriver) - 1] := #0;
GetProfileString('Devices', pchar(scboPrinter), '', pPort,
MAX_PATH);
lStrCpy(pPort, @pPort[lStrLen(pPort)+2]);
report.SelectPrinter(StrPas(pdriver),scboPrinter,StrPas(pPort));
report.SelectPrinter(StrPas(pdriver),scboPrinter,StrPas(pPort));
FreeMem(pDevice, cchDeviceName);
FreeMem(pDriver, MAX_PATH); <<<<<<<<<<<<<<<<<<Error Line
FreeMem(pPort, MAX_PATH);

Any ideas?
--
Tony Nasca
Dove Net Technologies, LLC
9126 Travener Circle, Suite 100
Frederick, MD 21704
301-874-9777 x 100 Fax 301-874-9767
www.dovenet.com
***@dovenet.com
Peter Below (TeamB)
2008-03-15 11:03:06 UTC
Permalink
Post by Anthony Nasca
GetMem(pDevice, cchDeviceName);
GetMem(pDriver, MAX_PATH);
GetMem(pPort, MAX_PATH);
GetProfileString('Devices', pchar(scboPrinter), '', pDriver,
MAX_PATH);
Post by Anthony Nasca
pDriver[pos(',', pDriver) - 1] := #0;
Consider what happens here if pDriver does not contain a ',' .....
Post by Anthony Nasca
GetProfileString('Devices', pchar(scboPrinter), '', pPort,
MAX_PATH);
What is that supposed to accomplish, other than a random memory
overwrite?

If the goal is to split the comma-separated list of strings returned by
GetProfileString do it this way:

GetMem(pDriver, MAX_PATH);
GetProfileString('Devices', pchar(scboPrinter), '', pDriver,
MAX_PATH);
pPort := StrScan(pDriver, ',');
if pPort = nil then
...raise an exception, there is no comma in this string
pPort^ := #0;
Inc(pPort);

DO NOT CALL FreeMem ON pPort!!! It just refers to a part of the pDriver
string.
--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
Loading...