Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory eater #107

Open
NimeCloud opened this issue Nov 2, 2012 · 2 comments
Open

Memory eater #107

NimeCloud opened this issue Nov 2, 2012 · 2 comments

Comments

@NimeCloud
Copy link

This code piece consumes the all memory in my 8GB PC.

            MailMessage msg = new MailMessage();
            msg.Load("x", false);
andyedinborough added a commit that referenced this issue Nov 2, 2012
@andyedinborough
Copy link
Owner

I’m working on this right now actually. Can you make a pull request so that your changes are highlighted?

Andy

From: NimeCloud [mailto:notifications@github.com]
Sent: Friday, November 2, 2012 8:32 AM
To: andyedinborough/aenetmail
Subject: Re: [aenetmail] Memory eater (#107)

ReadLine seems buggy and I modified it as below:

    //

    internal static string ReadLine(this Stream stream, ref int maxLength, Encoding encoding, char? termChar) {

    if (stream.CanTimeout)

        stream.ReadTimeout = 10000;



    var maxLengthSpecified = maxLength > 0;

    byte b = 0, b0;

    int current = 0; // <-- Added a counter



    using (var mem = new MemoryStream()) {

        while (true) {

            b0 = b;

            b = (byte)stream.ReadByte();

            if (maxLengthSpecified) maxLength--;



            if (maxLengthSpecified && mem.Length == 1 && b == termChar && b0 == termChar) {

                maxLength++;

                continue;

            }



            if (b == 10 || b == 13) {

                if (mem.Length == 0 && b == 10) {

                    continue;

                } else break;

            }



            mem.WriteByte(b);

            if (maxLengthSpecified && maxLength == 0)

                break;



            // Check the length

            current++;

            if (current >= mem.Length)

                break;



        }

        return encoding.GetString(mem.ToArray());

    }

}


Reply to this email directly or view it on GitHubhttps://github.com//issues/107#issuecomment-10014241.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@andyedinborough @NimeCloud and others