|
From: Andreas F. <and...@di...> - 2004-09-22 14:42:53
|
Hi,
the bug is that you are allocating room for only a pointer, not for a
structure of type LinkedList.
Regards,
Andreas
-----Original Message-----
From: val...@li...
[mailto:val...@li...] On Behalf Of Lucas
Brasilino
Sent: den 22 september 2004 16:23
To: val...@li...
Subject: [Valgrind-users] Valgrind point me out invalid writes I can't
see why.
Hi!
I think I'm messing out something, but can't figure out some
invalid writes valgrind pointing me out.
I'm implementing a linked list for a server I'm writing that will store
user configuration from a file. So I did:
struct _LinkedList
{
char *key;
char *data;
struct _LinkedList *next;
struct _LinkedList *head;
};
typedef struct _LinkedList LinkedList;
int main(void)
{
LinkedList *usersettings;
usersettings =3D newLinkedList();
}
LinkedList *newLinkedList(void)
{
LinkedList *s;
/* memory allocation for LinkedList structure */
s =3D (LinkedList *)malloc (sizeof (LinkedList *));
if (!s)
return s;
/* storing list's head */
s->head =3D s; /* invalid write ???? */
s->next =3D NULL; /* invalid write ???? */
s->key =3D NULL; /* Here valgrind says it's ok (no invalid write) */
s->data =3D NULL; /* invalid write ???? */
return s;
}
Any tip or help?
thanks a lot in advance:
--=20
[]'s
Lucas Brasilino
bra...@re...
http://www.recife.pe.gov.br
Emprel - Empresa Municipal de Informatica (pt_BR)
Municipal Computing Enterprise (en_US) Recife -
Pernambuco - Brasil
Fone: +55-81-34167078
-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
Valgrind-users mailing list
Val...@li...
https://lists.sourceforge.net/lists/listinfo/valgrind-users
|
|
From: Gao, J. <JG...@se...> - 2004-09-22 14:48:17
|
You allocate too few memory. The following:
s =3D (LinkedList *)malloc (sizeof (LinkedList *));
should change to:
s =3D (LinkedList *)malloc (sizeof (LinkedList));
-----Original Message-----
From: val...@li...
[mailto:val...@li...] On Behalf Of Lucas
Brasilino
Sent: Wednesday, September 22, 2004 10:23 AM
To: val...@li...
Subject: [Valgrind-users] Valgrind point me out invalid writes I can't
see why.
Hi!
I think I'm messing out something, but can't figure out
some invalid writes valgrind pointing me out.
I'm implementing a linked list for a server I'm writing that
will store user configuration from a file. So I did:
struct _LinkedList
{
char *key;
char *data;
struct _LinkedList *next;
struct _LinkedList *head;
};
typedef struct _LinkedList LinkedList;
int main(void)
{
LinkedList *usersettings;
usersettings =3D newLinkedList();
}
LinkedList *newLinkedList(void)
{
LinkedList *s;
/* memory allocation for LinkedList structure */
s =3D (LinkedList *)malloc (sizeof (LinkedList *));
if (!s)
return s;
/* storing list's head */
s->head =3D s; /* invalid write ???? */
s->next =3D NULL; /* invalid write ???? */
s->key =3D NULL; /* Here valgrind says it's ok (no invalid write) */
s->data =3D NULL; /* invalid write ???? */
return s;
}
Any tip or help?
thanks a lot in advance:
--=20
[]'s
Lucas Brasilino
bra...@re...
http://www.recife.pe.gov.br
Emprel - Empresa Municipal de Informatica (pt_BR)
Municipal Computing Enterprise (en_US)
Recife - Pernambuco - Brasil
Fone: +55-81-34167078
-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
Valgrind-users mailing list
Val...@li...
https://lists.sourceforge.net/lists/listinfo/valgrind-users
This message (including any attachments) contains confidential =
information intended for a specific individual and purpose, and is =
protected by law. If you are not the intended recipient, you should =
delete this message. Any disclosure, copying, or distribution of this =
message, or the taking of any action based on it, is strictly =
prohibited.
|