I have a table as follows:

```
ID   | col1 | Date Time
1    | WA   | 2/11/20
1    | CI   | 1/11/20
2    | CI   | 2/11/20
2    | WA   | 3/11/20
3    | WA   | 2/10/20
3    | WA   | 1/11/20
3    | WA   | 2/11/20
4    | WA   | 1/10/20
4    | CI   | 2/10/20
4    | SA   | 3/10/20

```

I want to find all ID values for which col1 had some other value in addition to WA as well and the most latest value in col1 should be 'WA'. i.e. from the sample data above , only ID values 1 & 2 should be returned. Because both of those have an additional value (i.e., CI) in additon to WA, but still the most latest value for them is WA.

How do I get that??

FYI, there could be some IDs that don't have WA value at all. I want to eliminate them. Also those that only have WA value, I want to eliminate those as well.

Thanks for the help.
['https://Stackoverflow.com/questions/60497943', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10096621/']
There are several problems here.

1. **You `delete[]` instead of `free`.**

`strdup` comes from the C library. [The documentation](https://en.cppreference.com/w/c/experimental/dynamic/strdup) tells us how to clean it up.

Microsoft's similar `_strdup` [works the same way](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strdup-wcsdup-mbsdup?view=vs-2019).

*You must read the documentation for functions that you use*, particularly if you're having trouble with them. That is why it is there.
2. **You invoke the destructor of `A` manually, when you shouldn't.**

The object has automatic storage duration, and will be destroyed automatically. When you for some reason call the destructor yourself, that means it'll be ultimately called *twice*. That means the erroneous deallocation call `delete[] myChar` will also be called twice, which is clearly worng.
3. **Your object's copy semantics are broken.**

Okay, so you don't copy it here. But any object that manages memory should follow the rule of zero, the rule of three, or the rule of five.
4. **You're checking for leaks too early.**

`myA` is still alive when you call `_CrtDumpMemoryLeaks()`, so of course it's going to see that it hasn't been destroyed/freed yet, and deem that to be a memory leak. You're supposed to call that function after you've attempted to rid yourself of all your resources, not before.

Here's your directly fixed code:

```
#include "pch.h"
#include <iostream>

class A
{
public:
    A(const char *fn) {
        myChar = _strdup(fn);
    }

    A(const A& other) {
        myChar = _strdup(other.myChar);
    }

    A& operator=(const A& other) {
        if (&other != this) {
           free(myChar);
           myChar = _strdup(other.myChar);
        }

        return *this;
    }

    ~A() {
       free(myChar);
    }

    char *myChar;
};

int main()
{
    {
       A myA("lala");
    }

    _CrtDumpMemoryLeaks(); //leak detector
}

```

And here's what it should have been:

```
#include <string>
#include <utility>   // for std::move
#include <crtdbg.h>  // for _CrtDumpMemoryLeaks

class A
{
public:
    A(std::string str) : m_str(std::move(str)) {}

private:
    std::string str;
};

int main()
{
   {
      A myA("lala");
   }

   _CrtDumpMemoryLeaks(); // leak detector
}

```
There are many different allocation schemes out there. Too many to just guess or assume how to free things. So you first look up the documentation on the function. Even just googling something like "msdn \_strdup" often gets there or close (for stuff that comes with Windows / Visual Studio / Microsoft).

<https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strdup-wcsdup-mbsdup?view=vs-2019>

> 
> The \_strdup function calls malloc to allocate storage space for a copy of strSource and then copies strSource to the allocated space.
> 
> 
> 

and

> 
> Because \_strdup calls malloc to allocate storage space for the copy of strSource, it is good practice always to release this memory by calling the free routine on the pointer that's returned by the call to \_strdup.
> 
> 
> 

So you need to use `free`