dangling

Why doesn't File::Find handle my dangling symlink?

I'm using Perl's File::Find module to scan for files, directories, and links. Among other things, I want the utility I'm writing to report dangling links. In theory, this is supported by creating a subroutine to be called whenever an dangling link has been found, and calling the find method with a hash reference of appropriate values, ...

In C++, what's the use of having a function void foo(int** p)?

Dear all, I have been told by my colleague that this is used like an out parameter in C#, can some precisely explain how? I get the idea, but there is something that is missing.. I know that if we pass the pointer itself p to foo (*p), and the function body does p = new int(), we might have a dangling modifier! what I don't get is how f...

Simple, efficient weak pointer that is set to NULL when target memory is deallocated

Is there a simple, efficient weak/guarded pointer? I need multiple pointers to the same object that are all automatically set to NULL when the object is deleted. There is one "master" pointer that is always used to delete the object, but there can be several other pointers that reference the same object. Here are some solutions that don...

Trouble with dangling pointers and character arrays in C

main(){ char *cmd1[20] = {NULL}; int x = parse_command(cmd1); printf("%s\ ",cmd1[0]); } parse_command(char *inTempString){ char tempString[256]; (call to function that assigns a string to tempString) cmd1[0] = tempString; } There is a problem when printing out the cmd1[0] within main. I am pretty sure that it is a da...

dangling pointer, reason for value change after free()?

In the following code segment, after free(x), why does y becomes 0? As per my understanding, the memory in the heap that was being pointed to by x, and is still being pointed by y, hasn't been allocated to someone else, so how can it change to 0? And moreover, I don't think it is free(x) that changed it to 0. Any comments? #include <...

Dangling pointers and double free

After some painful experiences, I understand the problem of dangling pointers and double free. I am seeking proper solutions. aStruct has a number of fields including other arrays. aStruct *A=NULL, *B = NULL; A = (aStruct*) calloc(1, sizeof(sStruct)); B = A; free_aStruct(A); ... //bunch of other code in various places. ... free_aStruct...

C++: Writing a function to free a pointer and the assigning it NULL

So I was asked this in a recent interview, basically writing a function to combine the free and Assigning null functionality. I answered in the following manner, void main() { int *ptr; ptr = new int; ptr = newdelete(ptr); } (int*) newdelete (int *ptr) { delete(ptr); return NULL; } So after execution, t...

C++ Problem with destructor called when removing element from STL container

Say I have 2 containers storing pointers to the same objects... std::list<Foo*> fooList; std::vector<Foo*> fooVec; Lets say I remove an object from one of these containers via one if its methods, for example... std::vector<Foo*>::iterator itr = std::find( fooVec.begin(), fooVec.end(), pToObj ); fooVec.erase( itr ); CppReference ...

c++ - dangling pointer example

Please explain why s1.printVal causes a dangling pointer error. Isn't the s1 object, i.e. its pointer, still accessible until it's destroyed? class Sample { public: int *ptr; Sample(int i) { ptr = new int(i); } ~Sample() { delete ptr; } void PrintVal() ...

Listing and deleting Git commits that are under no branch (dangling?)

I've got a git repository with plenty of commits that are under no particular branch, I can git show them but when I try to list branches that contain them, it reports back nothing: I thought this is the dangling commits/tree issue (as a result of -D branch), so I pruned the repo, but I still see the case after that: $ git fetch origin...