'android studio imageview using overload graphic

enter image description here

Code

Picasso.get().load(pImage).into(myHolder.post_img);

Please Help Me



Solution 1:[1]

The problem is here:

ptr = val;

Then both ptr and val will point to the same address, and you are a double free/delete on the same address.

I will try illustrate what's happening, let's assume 32bit addresses:

int main()
{   
    const int* ptr = new int();      // ptr allocate 4 bytes @ heap
                                     // for illustration purposes
                                     // ptr is @ address 0x80000010
    int* val=new int();              // val allocate 4 bytes @ heap
                                     // val is @ address 0x80000020
    ptr = val;                       // now ptr is @ address 0x80000020   
    std::cout << *val << std::endl;  // print out the int @ address 0x80000020   
    delete val;                      // free memory @ 0x80000020
    delete ptr;                      // free memory @ 0x80000020 - this will result in a double-free, 
                                     // no good, program will most likely crash
    
    return 0;
}  

NOTE: address 0x80000010 and 0x80000020 are just for example illustration, running this application for real the allocated addresses on heap will most likely be completely different.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Morgan V