OK, to be more specific, usually what happens (OS dependent, but AFAIK, it’s universal, maybe somewhere in the specification) is that somewhere in the command set of your executable file there are lines “ABC” and "CBA" - they are built into your program. When you do str="ABC" , you say: "I want this line pointer to point to an address in my compiled program containing the line ABC." That's why there is a difference between “strings” at run time and “string literals” if you see this in the documentation anywhere. Since you did not allocate space for your literal - the compiler baked it into your program - you do not need to free up space for it.
In any case, when your process is unloaded, the OS frees this resource as a natural side effect of unloading your program. In fact, in general, it is impossible to leak after the program is due to the OS freeing up any resources that you forgot, even disgusting leaks, when you exit the program. (this is not entirely true - you can force another program that does not download to leak if you linked the library material, but this is close enough). This is just one of those things that the OS cares about.
source share