Hi,
Valgrind detected memleak on one of my test case, which is
a standard, textbook insertion sort. However, I don't see
any problem with the testcase. I'm wondering if this is
a false alarm, and should submit a bug report.
I'm using SuSE 10.1, and valgrind-3.2.0-11.1 from opensuse build
service.
The followings are the test case and the output of valgrind.
I've marked the offending line (line 36) in the testcase.
/************************** Test Case ************************/
#include
#include
typedef struct _int_struct {
int i;
struct _int_struct *next;
} IntStruct;
typedef struct _int_list {
IntStruct *head;
} IntList;
int insert(IntList *ilist, int i);
int insertion_sort(IntList *ilist, IntStruct *is);
int main() {
IntStruct *is;
IntList ilist;
ilist.head = NULL;
insert(&ilist, 500);
insert(&ilist, 100);
printf("ilist: ");
for (is = ilist.head; is; is = is->next)
printf("%d ", is->i);
printf("\n");
return 0;
}
int insert(IntList *ilist, int i) {
IntStruct *is = (IntStruct *) calloc(1, sizeof(IntStruct)); /* line 36 */
is->i = i;
return insertion_sort(ilist, is);
}
int insertion_sort(IntList *ilist, IntStruct *is) {
IntStruct **isp;
for (isp = &ilist->head; *isp; isp = &((*isp)->next)) {
if (is->i < (*isp)->i) {
is->next = *isp;
break;
} else if (is->i == (*isp)->i) {
/* return FALSE; */
return 0;
}
}
*isp = is;
/* return TRUE; */
return 1;
}
/***********************************************************/
/************************ Valgrind Output ******************/
$ valgrind -q --leak-check=full ./a.out
ilist: 100 500
==15413==
==15413== 16 (8 direct, 8 indirect) bytes in 1 blocks are definitely lost in loss record 2 of 2
==15413== at 0x40206D5: calloc (vg_replace_malloc.c:279)
==15413== by 0x80484CD: insert (coba.c:36)
==15413== by 0x8048461: main (coba.c:24)
/***********************************************************/
--
Regards,
Verdi
--
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer