[Winpcap-users] pcap_freealldevs() causing program crash.

Eric Hansen nightskywriter at gmail.com
Wed Nov 16 20:51:41 GMT 2005


Wow...do I feel stupid...hehe.

It works now, and I can call freealldevs() in the Cleanup() code like I
orignally had, and it doesn't crash anymore.

Thank you very much Mr. Harris.

On 11/16/05, Guy Harris <guy at alum.mit.edu> wrote:
>
> Eric Hansen wrote:
>
> > What I do, is store the info like so:
> >
> > cDevice[iCount] = d->name;
>
> In C, that's not copying a string. That's copying the pointer *to* the
> string.
>
> Even in C++, it doesn't copy the string, it copies the pointer to the
> string - unless somehow operator overloading works on "char *", causing
> a copy of the string to be allocated and the copy assigned to
> cDevice[iCount].
>
> Unless somehow that operation causes a copy of the string pointed to by
> d->name to be made, and a pointer to that *copy* assigned to
> cDevice[iCount], then cdevice[iCount] will *NOT* be valid after
> pcap_freealldevs() is called.
>
> Try doing
>
> cDevice[iCount] = strdup(d->name);
>
> instead (make sure you include <string.h> to declare strdup()).
>
> (BTW, presumably you're growing the array if iCount is larger than its
> current size, or quitting once iCount reaches the size of the array,
> right?)
>
> > Then, when I goto list the info, I do this:
> >
> > for(i = 0; i < iCount; i++){
> > m_devices.AddString(cDevice[i]);
> > }
>
> Are you doing that *before* calling pcap_freealldevs()? If not, that
> won't work unless you're using strdup() to copy d->name (or whatever
> language environment you're using does that, or the equivalent of that,
> for you).
> _______________________________________________
> Winpcap-users mailing list
> Winpcap-users at winpcap.org
> https://www.winpcap.org/mailman/listinfo/winpcap-users
>



--
http://tenshi.honeyblade.net (my poetry)

"You wanted this ending to happen...ROMANTISUTO!"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.winpcap.org/pipermail/winpcap-users/attachments/20051116/aa4c7736/attachment.htm


More information about the Winpcap-users mailing list