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 leak if bad_alloc happens #27

Open
demin-dmitriy opened this issue Aug 4, 2017 · 0 comments
Open

Memory leak if bad_alloc happens #27

demin-dmitriy opened this issue Aug 4, 2017 · 0 comments

Comments

@demin-dmitriy
Copy link

Just want to note, that whenever you write code (you usually see this kind of thing in various tutorials) like this

    m_matrix = new T*[rows]; // rows
    for ( size_t i = 0 ; i < rows ; i++ ) {
      m_matrix[i] = new T[columns]; // columns
    }

you have a memory leak, because any of the new T[columns] can throw an exception.
Standard way to fix that is to either use std::unique_ptr or std::vector. But even better thing to do here is to use one std::vector of size columns * rows, because that will improve cache locality.

@demin-dmitriy demin-dmitriy changed the title Memory leak Memory leak when bad_alloc Aug 4, 2017
@demin-dmitriy demin-dmitriy changed the title Memory leak when bad_alloc Memory leak if bad_alloc happens Aug 4, 2017
Gluttton added a commit to Gluttton/munkres-cpp that referenced this issue Feb 5, 2022
Make deleted functions (copy constructor and assignment operator)
public, because preserving them private hides the original intention.

Issue: saebyn#27
Signed-off-by: Gluttton <gluttton@ukr.net>
Gluttton added a commit to Gluttton/munkres-cpp that referenced this issue Nov 5, 2022
Make deleted functions (copy constructor and assignment operator)
public, because preserving them private hides the original intention.

Issue: saebyn#27
Signed-off-by: Gluttton <gluttton@ukr.net>
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

1 participant