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

Prevent return of dangling Vector/QAngle to VScript #321

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Commits on Sep 5, 2024

  1. Prevent return of dangling Vector/QAngle to VScript

    When a Vector or QAngle rvalue reference is returned from a VScript
    function, the constructed ScriptVariant_t must not store the pointer to
    it since it is, per convention, a temporary reference. Only do that for
    lvalue-references, but do a copy when constructing from or assigning a
    rvalue reference.
    z33ky committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    c9dd357 View commit details
    Browse the repository at this point in the history

Commits on Nov 15, 2024

  1. "Fix" ScriptVariant_t::Free()

    Type FIELD_HSCRIPT is removed, it never sets SV_FREE.
    
    All dynamic memory is now free`d via free(). For strdup(), this would be
    the conformant way in standard C++. It matters not in Source, since both
    use the same global allocator of the engine, but it is tidier.
    Vector and QAngle are now allocated via malloc() instead of new to
    provide symmetry.
    z33ky committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    80f1960 View commit details
    Browse the repository at this point in the history
  2. Fix dubious ScriptVariant_t Free()'s

    When assigning a null value in getVariant(), make sure a previous
    SV_FREE is not carried over.
    
    In SqurrelVM::ReleaseValue(), make sure SV_FREE is not kept after
    Free()ing a value.
    z33ky committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    879b9e8 View commit details
    Browse the repository at this point in the history
  3. Optimize squirrel function_stub() Vector/QAngle return value

    Instead of temporary allocating dynamic memory, which subsequently is
    copied into another dynamically allocated piece of memory, provide a
    temporary buffer on the stack.
    The script value inserted into the VM still needs to allocate
    dynamically though...
    
    A few sites are adapted to not create a ScriptVariant_t from a temporary
    Vector to avoid dynamic allocation there too.
    
    cf. mapbase-source#321
    z33ky committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    0123813 View commit details
    Browse the repository at this point in the history
  4. Remove unused generic ScriptVariant_t::{Get,AssignTo}()

    They wouldn't even work.
    z33ky committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    4d485d2 View commit details
    Browse the repository at this point in the history
  5. Fix (potential?) memory leaks from getVariant() (SquirrelVM)

    Free values before assignment.
    z33ky committed Nov 15, 2024
    Configuration menu
    Copy the full SHA
    cdb8de8 View commit details
    Browse the repository at this point in the history