473,320 Members | 1,744 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

gethostbyname() ---- Delete Resulting Pointer?

aj
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?
Dec 6 '07 #1
18 3619
On Dec 6, 10:36 am, aj <a...@bookac.comwrote:
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
Dec 6 '07 #2
On Dec 6, 1:36 pm, aj <a...@bookac.comwrote:
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
Dec 6 '07 #3
aj
On Dec 6, 2:14 pm, Lew Pitcher <lpitc...@teksavvy.comwrote:
On Dec 6, 1:36 pm, aj <a...@bookac.comwrote:
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.
Dec 6 '07 #4
aj <aj@bookac.comwrites:
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.
Dec 6 '07 #5
On Dec 6, 2:23 pm, aj <a...@bookac.comwrote:
On Dec 6, 2:14 pm, Lew Pitcher <lpitc...@teksavvy.comwrote:
On Dec 6, 1:36 pm, aj <a...@bookac.comwrote:
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?
Dec 6 '07 #6
"aj" <aj@bookac.comschrieb im Newsbeitrag
news:82**********************************@s36g2000 prg.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
Dec 6 '07 #7
"aj" <aj@bookac.comschrieb im Newsbeitrag
news:35**********************************@e25g2000 prg.googlegroups.com...
On Dec 6, 2:14 pm, Lew Pitcher <lpitc...@teksavvy.comwrote:
>On Dec 6, 1:36 pm, aj <a...@bookac.comwrote:
....
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
Dec 6 '07 #8
aj
On Dec 6, 2:39 pm, "Joachim Schmitz" <nospam.j...@schmitz-digital.de>
wrote:
"aj" <a...@bookac.comschrieb im Newsbeitragnews:35******************************** **@e25g2000prg.googlegroups.com...On Dec 6, 2:14 pm, Lew Pitcher <lpitc...@teksavvy.comwrote:
On Dec 6, 1:36 pm, aj <a...@bookac.comwrote:
...
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.
Dec 6 '07 #9
On Dec 6, 2:59 pm, aj <a...@bookac.comwrote:
On Dec 6, 2:39 pm, "Joachim Schmitz" <nospam.j...@schmitz-digital.de>
wrote:
"aj" <a...@bookac.comschrieb im Newsbeitragnews:35******************************** **@e25g2000prg.googlegroups.com...On Dec 6, 2:14 pm, Lew Pitcher <lpitc...@teksavvy.comwrote:
>On Dec 6, 1:36 pm, aj <a...@bookac.comwrote:
...
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.
When you provided example code that could not be C (even though you
say that you compile it with a C compiler) and stated that
I am under the impression that you don't delete anything unless you
personally "new'ed" it. Is this theory correct in this situation?
you took the question out of the realm of the C language.

How can we correctly answer the (implied) question of "Is the theory
that you don't delete anything unless you personally 'new'ed it?" when
the C language does not recognize the concept of "new"ing anything,
nor of "delete"ing anything? You are asking a question (apparently)
about the C++ language, and the responsibility of a C++ programmer to
write correct C++ programs. That question we cannot answer.

Had you asked
"Is the theory that you don't free() anyting unless you've personally
malloc()ed (or calloc()ed or realloc()ed) it?"
then we could have answered, for your question would be answerable
within the confines of the C language and best-practices of C
programming.

Just so you know...
Dec 6 '07 #10
In <35**********************************@e25g2000prg. googlegroups.comaj <aj@bookac.comwrites:
As usual, you guys are no help, just sticklers for details.
One would infer that when you have the flu, you go to your local grocery
store and ask a stockboy what to do about it, and are offended when he
suggests you ask a doctor.

--
John Gordon A is for Amy, who fell down the stairs
go****@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

Dec 6 '07 #11
aj
On Dec 6, 3:22 pm, Lew Pitcher <lpitc...@teksavvy.comwrote:
On Dec 6, 2:59 pm, aj <a...@bookac.comwrote:


On Dec 6, 2:39 pm, "Joachim Schmitz" <nospam.j...@schmitz-digital.de>
wrote:
"aj" <a...@bookac.comschrieb im Newsbeitragnews:35******************************** **@e25g2000prg.googlegrou-ps.com...On Dec 6, 2:14 pm, Lew Pitcher <lpitc...@teksavvy.comwrote:
On Dec 6, 1:36 pm, aj <a...@bookac.comwrote:
...
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.

When you provided example code that could not be C (even though you
say that you compile it with a C compiler) and stated thatI am under the impression that you don't delete anything unless you
personally "new'ed" it. Is this theory correct in this situation?

you took the question out of the realm of the C language.

How can we correctly answer the (implied) question of "Is the theory
that you don't delete anything unless you personally 'new'ed it?" when
the C language does not recognize the concept of "new"ing anything,
nor of "delete"ing anything? You are asking a question (apparently)
about the C++ language, and the responsibility of a C++ programmer to
write correct C++ programs. That question we cannot answer.

Had you asked
"Is the theory that you don't free() anyting unless you've personally
malloc()ed (or calloc()ed or realloc()ed) it?"
then we could have answered, for your question would be answerable
within the confines of the C language and best-practices of C
programming.

Just so you know...- Hide quoted text -

- Show quoted text -
Lew,

I understand your point. You are right, the sample program I
provided is not pure C. I should have removed the "delete" call prior
to posting, and should have rephrased the question to be more C'ish.
That being said, I have come to conclusion that I am not responsible
for the resulting memory, and have removed the delete call.

Thanks,
AJ
Dec 6 '07 #12
aj
On Dec 6, 3:25 pm, John Gordon <gor...@panix.comwrote:
In <35d5bb8d-2d2f-475e-97ef-2de910761...@e25g2000prg.googlegroups.comaj <a...@bookac.comwrites:
As usual, you guys are no help, just sticklers for details.

One would infer that when you have the flu, you go to your local grocery
store and ask a stockboy what to do about it, and are offended when he
suggests you ask a doctor.

--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
Acknowledged. Except you guys aren't stockboys. Stockboys don't know
what to do about the flu. You hardened C types, however, have the
knowledge to provide insight into my dilemna, so I dismiss your
analogy ;) !

Dec 6 '07 #13
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
Dec 6 '07 #14
aj wrote, On 06/12/07 19:59:
On Dec 6, 2:39 pm, "Joachim Schmitz" <nospam.j...@schmitz-digital.de>
wrote:
>"aj" <a...@bookac.comschrieb im Newsbeitragnews:35******************************** **@e25g2000prg.googlegroups.com...On Dec 6, 2:14 pm, Lew Pitcher <lpitc...@teksavvy.comwrote:
>>>On Dec 6, 1:36 pm, aj <a...@bookac.comwrote:
...
>>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".
Your code used delete and your question mentioned them, and they are
enough to show that your code is NOT C code.
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.
That is almost forgiveable, but basic research (i.e. reading the man
page since you mentioned this was a problem on Linux) would have shown
you that it is not standard C.
Regardless, it is still C
syntax, compiled by a C compiler.
Any C compiler when operating as a C compiler would have rejected your
code because it was not C code. As you were told new and delete are not
part of C.
I will save future (read: all)
questions for a more appropriate newsgroup. Sorry you felt the need
to plonk me.
Well, you've saved me from having to plonk you. Had I seen this post
earlier I would not have bothered with the post telling you the correct
group to ask in.
--
Flash Gordon
Dec 6 '07 #15
Lew Pitcher wrote:
Sorry, but C does not have
- a keyword called "delete",
- a keyword called "new"
- a standard function called gethostbyname()
- a standard struture called hostent
You probably want to discuss this topic in comp.lang.c++
As C++ is missing items 3 and 4, that seems unlikely.

Brian
Dec 6 '07 #16
aj wrote:

As usual, you guys are no help, just sticklers for details.
Another idiot to plonk.


Brian
Dec 6 '07 #17
aj wrote:
Lew Pitcher <lpitc...@teksavvy.comwrote:
>aj <a...@bookac.comwrote:
>>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?
.... snip ...
>>
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++

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

Thanks for the non-help.
Congratulations. Your second post attained PLONK status. A new
record here.

PLONK

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Dec 7 '07 #18
aj wrote:
>
On Dec 6, 3:25 pm, John Gordon <gor...@panix.comwrote:
In <35d5bb8d-2d2f-475e-97ef-2de910761...@e25g2000prg.googlegroups.comaj <a...@bookac.comwrites:
As usual, you guys are no help, just sticklers for details.
One would infer that when you have the flu, you go to your local grocery
store and ask a stockboy what to do about it, and are offended when he
suggests you ask a doctor.

Acknowledged. Except you guys aren't stockboys. Stockboys don't know
what to do about the flu. You hardened C types, however, have the
knowledge to provide insight into my dilemna, so I dismiss your
analogy ;) !
Perhaps this wording is better?

One would infer that when you have a strange growth on your arm,
you go to your local medical building and ask a pediatrician what
to do about it, and are offended when he suggests you ask a
dermatologist or oncologist. ("You guys are no help, just
sticklers for details.")

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Dec 7 '07 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.