473,396 Members | 2,151 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,396 software developers and data experts.

memprof errors

I am trying to use memprof-0.5.1(because apt-get memprof gives me this
version, although I know version 0.6 came out recently) to debug my
program. My Linux box is a ubuntu, here I list its
kernel/glibc/linker/compiler info
--------------------------------------------------
uname -a
=Linux 2.6.16.27-gg1-em64t #1 SMP
getconf GNU_GLIBC_VERSION
=>glibc 2.3.5
ld --version
=>GNU ld version 2.16.1 Debian GNU/Linux
Copyright 2005 Free Software Foundation, Inc
gcc --version
=>gcc (GCC) 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu9)
memprof --version
=>memprof 0.5.1
--------------------------------------------------

When I test this following simple case by
#gcc -o mytest -g main.c
#memprof mytest
The system hang there when I select File->Run Program->(select mytest),
and also an error message popped up in the console:
*** glibc detected *** free(): invalid pointer: 0x4e401580 ***

-----------------main.c------------------------
#include <stdlib.h>
#include <stdio.h>
void foo(){
int i = 0, j = 8, k = 0;
for(i = 0 ; i < 20; i ++){
malloc(100);
k = j;
while(j < 2*k){
j++;
}
j = 2*k;
printf("k = %d\n", k);
}
}

int main(){
int i = 0, j =2;
for(i = 0; i < 10; i++){
j = j * 2;
foo();
}
}

----------end of main.c -----------------

Oct 3 '06 #1
3 1969

Sean wrote:
When I test this following simple case by
#gcc -o mytest -g main.c
#memprof mytest
The system hang there when I select File->Run Program->(select mytest),
and also an error message popped up in the console:
*** glibc detected *** free(): invalid pointer: 0x4e401580 ***

-----------------main.c------------------------
#include <stdlib.h>
#include <stdio.h>
void foo(){
int i = 0, j = 8, k = 0;
for(i = 0 ; i < 20; i ++){
malloc(100);
Which pointer points to the newly allocated memory? And what do you
want to do if malloc() fails?
k = j;
while(j < 2*k){
j++;
}
j = 2*k;
printf("k = %d\n", k);
}
}

int main(){
int i = 0, j =2;
for(i = 0; i < 10; i++){
j = j * 2;
foo();
}
}

----------end of main.c -----------------
You allocated lots of memory(nearly 20M), but why don't you free them
at the end?
If you can answer those questions, you will know why memprof complains.

Oct 3 '06 #2

Cong Wang wrote:
Sean wrote:
When I test this following simple case by
#gcc -o mytest -g main.c
#memprof mytest
The system hang there when I select File->Run Program->(select mytest),
and also an error message popped up in the console:
*** glibc detected *** free(): invalid pointer: 0x4e401580 ***

-----------------main.c------------------------
#include <stdlib.h>
#include <stdio.h>
void foo(){
int i = 0, j = 8, k = 0;
for(i = 0 ; i < 20; i ++){
malloc(100);

Which pointer points to the newly allocated memory? And what do you
want to do if malloc() fails?
k = j;
while(j < 2*k){
j++;
}
j = 2*k;
printf("k = %d\n", k);
}
}

int main(){
int i = 0, j =2;
for(i = 0; i < 10; i++){
j = j * 2;
foo();
}
}

----------end of main.c -----------------

You allocated lots of memory(nearly 20M), but why don't you free them
at the end?
If you can answer those questions, you will know why memprof complains.
I tried to use this to find memory leakage (well, foo() in this program
is such a case).
Actually, even I free the memory as follows, the memprof hangs there as
is.

Thanks,

--------------------------------------------------
#include <stdlib.h>
#include <stdio.h>

void foo(){
int i = 0, j = 8, k = 0;
char* p;
for(i = 0 ; i < 20; i ++){
p = malloc(100);
k = j;
while(j < 2*k){
j++;
}
j = 2*k;
sleep(1);
printf("k = %d\n", k);
free(p);
}
}

int main(){
int i = 0, j =2;
for(i = 0; i < 10; i++){
j = j * 2;
foo();
}
}
------------------------------------------------

Oct 3 '06 #3

Sean wrote:
Cong Wang wrote:
Sean wrote:
When I test this following simple case by
#gcc -o mytest -g main.c
#memprof mytest
The system hang there when I select File->Run Program->(select mytest),
and also an error message popped up in the console:
*** glibc detected *** free(): invalid pointer: 0x4e401580 ***
>
-----------------main.c------------------------
#include <stdlib.h>
#include <stdio.h>
void foo(){
int i = 0, j = 8, k = 0;
for(i = 0 ; i < 20; i ++){
malloc(100);
Which pointer points to the newly allocated memory? And what do you
want to do if malloc() fails?
k = j;
while(j < 2*k){
j++;
}
j = 2*k;
printf("k = %d\n", k);
}
}
>
int main(){
int i = 0, j =2;
for(i = 0; i < 10; i++){
j = j * 2;
foo();
}
}
>
----------end of main.c -----------------
You allocated lots of memory(nearly 20M), but why don't you free them
at the end?
If you can answer those questions, you will know why memprof complains.
I tried to use this to find memory leakage (well, foo() in this program
is such a case).
Actually, even I free the memory as follows, the memprof hangs there as
is.

Thanks,

--------------------------------------------------
#include <stdlib.h>
#include <stdio.h>

void foo(){
int i = 0, j = 8, k = 0;
char* p;
for(i = 0 ; i < 20; i ++){
p = malloc(100);
k = j;
while(j < 2*k){
j++;
}
j = 2*k;
sleep(1);
printf("k = %d\n", k);
free(p);
}
}

int main(){
int i = 0, j =2;
for(i = 0; i < 10; i++){
j = j * 2;
foo();
}
}
------------------------------------------------
Again, you forgot to check whether the return value of malloc() is
non-NULL.

And I use valgrind to check your program, it says:

ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 12 from 1)
malloc/free: in use at exit: 0 bytes in 0 blocks.
malloc/free: 200 allocs, 200 frees, 20,000 bytes allocated.
For counts of detected errors, rerun with: -v
No malloc'd blocks -- no leaks are possible.

;-p

Oct 3 '06 #4

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

Similar topics

11
by: mikey_boy | last post by:
Hello! Curious if anyone could give me a hand. I wrote this PHP script with makes a simple connection to a mysql database called firstdb and just pulls back the results and displays on the...
2
by: Trev | last post by:
SQL Server 2000 BE, Access 2002 FE. I want to write a stored procedure, that will among other things log errors to a table, I want to be able to report a summary of work done and errors to the...
10
by: Douglas Buchanan | last post by:
I am using the following code instead of a very lengthly select case statement. (I have a lot of lookup tables in a settings form that are selected from a ListBox. The data adapters are given a...
0
by: doli | last post by:
Hi, I have the following piece of code which iterates through the potential errors: i =0 For Each error_item in myConn.Errors DTSPackageLog.WriteStringToLog myConn.Errors(i).Description...
4
by: johnb41 | last post by:
I have a form with a bunch of textboxes. Each text box gets validated with the ErrorProvider. I want the form to process something ONLY when all the textboxes are valid. I found a solution,...
24
by: pat | last post by:
Hi everyone, I've got an exam in c++ in two days and one of the past questions is as follows. Identify 6 syntax and 2 possible runtime errors in this code: class demo {
8
by: ImOk | last post by:
I just have a question about trapping and retrying errors especially file locking or database locks or duplicate key errors. Is there a way after you trap an error to retry the same line that...
1
by: Sean | last post by:
I am trying to use memprof-0.5.1(because apt-get memprof gives me this version, although I know version 0.6 came out recently) to debug my program. My Linux box is a ubuntu, here I list its...
3
by: Sean | last post by:
I am trying to use memprof-0.5.1(because apt-get memprof gives me this version, although I know version 0.6 came out recently) to debug my program. My Linux box is a ubuntu, here I list its...
2
by: =?Utf-8?B?UmFuZHlz?= | last post by:
This just started when I updated to sp 1 working on a APS.net, Visual Studio 2008, c# Project. When I open a project, I get tons of Errors showing in the list 300+ if I double click on them I go...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.