jain-sip icon indicating copy to clipboard operation
jain-sip copied to clipboard

Process is taking huge memory due to creation of 2 billion character "<".

Open Sujith-G opened this issue 6 years ago • 0 comments

Issue: Process is taking huge memory due to creation of 2 billion character "<". This will also lead to OutOfMemoryError within the process.

Reason: In Class MediaFieldParser.java -- MediaFieldParser.mediaField() if (Debug.parserDebug) Check is missing in the below code. dbg_leave("mediaField"); is being called without the 'if (Debug.parserDebug)' check.

    } finally {
        dbg_leave("mediaField");
    }

ParserCore.dbg_enter(String rule) are not called since debugging is not enabled at the process. In ParserCore.dbg_leave(String rule) nesting_level variable will be decremented by one every functioncall. Finally after 2147483647 function calls, The nesting_level variable will have -2147483648. On the next function call -2147483648 -1, Will nesting_level variable will have the value of 2147483647. This leads to the creation of 2147483647 characters '<' .

protected void dbg_leave(String rule) {
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i < nesting_level ; i++)
        stringBuilder.append("<");

    if (debug)  {
        System.out.println(
            stringBuilder +
            rule +
            "\nlexer buffer = \n" +
            lexer.getRest());
    }
    nesting_level --;
}

Fix: Please add if (Debug.parserDebug) in MediaFieldParser.mediaField(). } finally { if (Debug.parserDebug) dbg_leave("mediaField"); }

Sujith-G avatar Feb 06 '19 05:02 Sujith-G