Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   gethostbyname() ---- Delete Resulting Pointer? (http://www.velocityreviews.com/forums/t557862-gethostbyname-delete-resulting-pointer.html)

aj 12-06-2007 06:36 PM

gethostbyname() ---- Delete Resulting Pointer?
 
I have the following snippet of code. On some platforms, the delete
calls works, on Linux, it core dumps (memory dump) at the delete
call. Am I responsible for deleting the memory that gethostbyname
allocated?

struct hostent *lHostInfo;
lHostInfo = gethostbyname(ipHost.c_str());
memcpy(&(lDestAddr.sin_addr), lHostInfo->h_addr_list[0], lHostInfo-
>h_length);

delete lHostInfo;

I am under the impression that you don't delete anything unless you
personally "new'ed" it. Is this theory correct in this situation?

fred.l.kleinschmidt@boeing.com 12-06-2007 07:13 PM

Re: gethostbyname() ---- Delete Resulting Pointer?
 
On Dec 6, 10:36 am, aj <a...@bookac.com> wrote:
> I have the following snippet of code. On some platforms, the delete
> calls works, on Linux, it core dumps (memory dump) at the delete
> call. Am I responsible for deleting the memory that gethostbyname
> allocated?
>
> struct hostent *lHostInfo;
> lHostInfo = gethostbyname(ipHost.c_str());
> memcpy(&(lDestAddr.sin_addr), lHostInfo->h_addr_list[0], lHostInfo->h_length);
>
> delete lHostInfo;
>
> I am under the impression that you don't delete anything unless you
> personally "new'ed" it. Is this theory correct in this situation?


There is no 'new' or 'delete' in the C language.

gethostbyname is not defined by the C standard.

--
Fred Kleinschmdit

Lew Pitcher 12-06-2007 07:14 PM

Re: gethostbyname() ---- Delete Resulting Pointer?
 
On Dec 6, 1:36 pm, aj <a...@bookac.com> wrote:
> I have the following snippet of code. On some platforms, the delete
> calls works, on Linux, it core dumps (memory dump) at the delete
> call. Am I responsible for deleting the memory that gethostbyname
> allocated?
>
> struct hostent *lHostInfo;
> lHostInfo = gethostbyname(ipHost.c_str());
> memcpy(&(lDestAddr.sin_addr), lHostInfo->h_addr_list[0], lHostInfo->h_length);
>
> delete lHostInfo;
>
> I am under the impression that you don't delete anything unless you
> personally "new'ed" it. Is this theory correct in this situation?


Sorry, but C does not have
- a keyword called "delete",
- a keyword called "new"
- a standard function called gethostbyname()
- a standard struture called hostent

I suspect that you are writing C++ code (your mention of "new" and
"delete", and your use of method calls in your example code), which is
off-topic in comp.lang.c

You probably want to discuss this topic in comp.lang.c++

HTH
--
Lew

aj 12-06-2007 07:23 PM

Re: gethostbyname() ---- Delete Resulting Pointer?
 
On Dec 6, 2:14 pm, Lew Pitcher <lpitc...@teksavvy.com> wrote:
> On Dec 6, 1:36 pm, aj <a...@bookac.com> wrote:
>
> > I have the following snippet of code. On some platforms, the delete
> > calls works, on Linux, it core dumps (memory dump) at the delete
> > call. Am I responsible for deleting the memory that gethostbyname
> > allocated?

>
> > struct hostent *lHostInfo;
> > lHostInfo = gethostbyname(ipHost.c_str());
> > memcpy(&(lDestAddr.sin_addr), lHostInfo->h_addr_list[0], lHostInfo->h_length);

>
> > delete lHostInfo;

>
> > I am under the impression that you don't delete anything unless you
> > personally "new'ed" it. Is this theory correct in this situation?

>
> Sorry, but C does not have
> - a keyword called "delete",
> - a keyword called "new"
> - a standard function called gethostbyname()
> - a standard struture called hostent
>
> I suspect that you are writing C++ code (your mention of "new" and
> "delete", and your use of method calls in your example code), which is
> off-topic in comp.lang.c
>
> You probably want to discuss this topic in comp.lang.c++
>
> HTH
> --
> Lew


As usual, you guys are no help, just sticklers for details.

Thanks for the non-help.

Ben Bacarisse 12-06-2007 07:23 PM

Re: gethostbyname() ---- Delete Resulting Pointer?
 
aj <aj@bookac.com> writes:

> I have the following snippet of code. On some platforms, the delete
> calls works, on Linux, it core dumps (memory dump) at the delete
> call. Am I responsible for deleting the memory that gethostbyname
> allocated?


You are doubly off-topic. delete in C++, not C, and gethostbyname is
a *nix function. If you want to post somewhere, I'd choose
comp.unix.programmer, but man gethostbyname would be quicker (the
delete is wrong, BTW).

--
Ben.

Lew Pitcher 12-06-2007 07:27 PM

Re: gethostbyname() ---- Delete Resulting Pointer?
 
On Dec 6, 2:23 pm, aj <a...@bookac.com> wrote:
> On Dec 6, 2:14 pm, Lew Pitcher <lpitc...@teksavvy.com> wrote:
>
>
>
> > On Dec 6, 1:36 pm, aj <a...@bookac.com> wrote:

>
> > > I have the following snippet of code. On some platforms, the delete
> > > calls works, on Linux, it core dumps (memory dump) at the delete
> > > call. Am I responsible for deleting the memory that gethostbyname
> > > allocated?

>
> > > struct hostent *lHostInfo;
> > > lHostInfo = gethostbyname(ipHost.c_str());
> > > memcpy(&(lDestAddr.sin_addr), lHostInfo->h_addr_list[0], lHostInfo->h_length);

>
> > > delete lHostInfo;

>
> > > I am under the impression that you don't delete anything unless you
> > > personally "new'ed" it. Is this theory correct in this situation?

>
> > Sorry, but C does not have
> > - a keyword called "delete",
> > - a keyword called "new"
> > - a standard function called gethostbyname()
> > - a standard struture called hostent

>
> > I suspect that you are writing C++ code (your mention of "new" and
> > "delete", and your use of method calls in your example code), which is
> > off-topic in comp.lang.c

>
> > You probably want to discuss this topic in comp.lang.c++

>
> > HTH
> > --
> > Lew

>
> As usual, you guys are no help, just sticklers for details.
>
> Thanks for the non-help.


You're welcome.

After all, what else is comp.lang.C here for, but to *not* discuss
COBOL, JAVA, C++, .NET, C#, how to tune your car, oriental cooking,
and observance of the Jewish faith?

Joachim Schmitz 12-06-2007 07:33 PM

Re: gethostbyname() ---- Delete Resulting Pointer?
 
"aj" <aj@bookac.com> schrieb im Newsbeitrag
news:821a499a-9d57-44cb-9330-fcd7b3ae6342@s36g2000prg.googlegroups.com...
>I have the following snippet of code. On some platforms, the delete
> calls works, on Linux, it core dumps (memory dump) at the delete
> call. Am I responsible for deleting the memory that gethostbyname
> allocated?
>
> struct hostent *lHostInfo;
> lHostInfo = gethostbyname(ipHost.c_str());
> memcpy(&(lDestAddr.sin_addr), lHostInfo->h_addr_list[0], lHostInfo-
>>h_length);

> delete lHostInfo;
>
> I am under the impression that you don't delete anything unless you
> personally "new'ed" it. Is this theory correct in this situation?

for gethostbyname() ask in comp.unix.programmer, it's not topical here

for new/delete ask in comp.lang.c++ as neither exists in C, although I think
that a delete without a corresponding new won't work.

Bye, Jojo



Joachim Schmitz 12-06-2007 07:39 PM

Re: gethostbyname() ---- Delete Resulting Pointer?
 
"aj" <aj@bookac.com> schrieb im Newsbeitrag
news:35d5bb8d-2d2f-475e-97ef-2de910761df8@e25g2000prg.googlegroups.com...
> On Dec 6, 2:14 pm, Lew Pitcher <lpitc...@teksavvy.com> wrote:
>> On Dec 6, 1:36 pm, aj <a...@bookac.com> wrote:

....
> As usual, you guys are no help, just sticklers for details.
>
> Thanks for the non-help.

And you believe that this statement helps in getting helped? I guess this
just helps in getting you plonked...

You've been given all help there is, within topicalitiy of this group, which
in this case it pointing you to the groups where you might find help

Bye, Jojo



aj 12-06-2007 07:59 PM

Re: gethostbyname() ---- Delete Resulting Pointer?
 
On Dec 6, 2:39 pm, "Joachim Schmitz" <nospam.j...@schmitz-digital.de>
wrote:
> "aj" <a...@bookac.com> schrieb im Newsbeitragnews:35d5bb8d-2d2f-475e-97ef-2de910761df8@e25g2000prg.googlegroups.com...> On Dec 6, 2:14 pm, Lew Pitcher <lpitc...@teksavvy.com> wrote:
> >> On Dec 6, 1:36 pm, aj <a...@bookac.com> wrote:

> ...
> > As usual, you guys are no help, just sticklers for details.

>
> > Thanks for the non-help.

>
> And you believe that this statement helps in getting helped? I guess this
> just helps in getting you plonked...
>
> You've been given all help there is, within topicalitiy of this group, which
> in this case it pointing you to the groups where you might find help
>
> Bye, Jojo


My question wasn't about "delete" or "new". My question was if I am
responsible for deallocating the pointer provided by a certain
function. I wasn't aware that that particular function,
gethostbyname(), isn't in the C standard. Regardless, it is still C
syntax, compiled by a C compiler. I will save future (read: all)
questions for a more appropriate newsgroup. Sorry you felt the need
to plonk me.

Flash Gordon 12-06-2007 08:21 PM

Re: gethostbyname() ---- Delete Resulting Pointer?
 
aj wrote, On 06/12/07 18:36:

Firstly gethostbyname is not part of standard C so questions about it
would be better directed to a group dedicated to your platform such as
comp.unix.programmer, but before you do that you should at least do some
basic research, such as reading the man page for the function.

> I have the following snippet of code. On some platforms, the delete
> calls works, on Linux, it core dumps (memory dump) at the delete
> call. Am I responsible for deleting the memory that gethostbyname
> allocated?
>
> struct hostent *lHostInfo;
> lHostInfo = gethostbyname(ipHost.c_str());
> memcpy(&(lDestAddr.sin_addr), lHostInfo->h_addr_list[0], lHostInfo-
>> h_length);

> delete lHostInfo;
>
> I am under the impression that you don't delete anything unless you
> personally "new'ed" it. Is this theory correct in this situation?


Secondly delete C++ and not C. You need to decide which language you are
using since there are major differences (delete being one of them) and
stick to it and not post questions to do with C++ here.
--
Flash Gordon


All times are GMT. The time now is 09:47 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57