BADF00D / DisposableFixer

This is a Visual Studio Extension and NuGet package that should identify and fix problems as memleaks while using IDisposables.
Other
35 stars 7 forks source link

If disposable from factory is stored locally and afterwards return, there is an diagnostics #24

Closed dscopra closed 7 years ago

dscopra commented 7 years ago
public ISerialDevice OpenBySerialNumber(string serial, SerialPortSettings settings) {
    var device = OpenBySerialNumber(serial);
    try {
        var read_timeout = (uint) settings.ReadTimeout.TotalMilliseconds;
        var write_timeout = (uint) settings.WriteTimeout.TotalMilliseconds;

        device.SetBaudRate(settings.BaudRate);
        device.SetDataCharacteristics(settings.DataBits, settings.StopBits, settings.Parity);
        device.SetTimeoutsInMillis(read_timeout, write_timeout);
        device.SetFlowControl(settings.FlowControl);
        /* Eingangspuffer leeren, um eventuelle Restdaten aus
         * vorherigen Verbindungsversuchen nicht zu verarbeiten */
        device.Purge(PurgeFlags.Rx);

        return device;
    } catch (Exception) {
        SafeDispose(device);
        throw;
    }
}

image