Chrashing while trying to read the file from httpd server
Sangita P <[email protected]> Fri, 7 Mar 2008 05:07:52 +0000 (GMT)
| Newsgroups | gmane.linux.upnp-sdk.general |
|---|---|
| Message-ID | <[email protected]> |
--===============0501821582==
Content-Type: multipart/alternative; boundary="0-489124388-1204866472=:98513"
Content-Transfer-Encoding: 7bit
--0-489124388-1204866472=:98513
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Hi All,
I am using http client of libupnp-1.4.6.
Note : Linux version which I am using is fedora core 6.
When I tried to read the file from httpd server with test application.=20
Test Application:
#include<stdio.h>
#include<upnp.h>
int main(int argc,char * argv[])
{
char *url_str_a =3D "http://localhost/filename.mts";
void * Handle_a ;
char contentType_a ;
int contentLength_a ;
int httpStatus_a ;
int timeout_a =3D 1;
char *buf_a =3D (char *) malloc(2048);
unsigned int sizeOfBuffer =3D 2048 ,ReadRemainingBytes =3D 0;
int ReadBytes =3D0 ;
int retVal =3D 0;
if(UPNP_E_SUCCESS =3D=3D UpnpInit(NULL,80))
{
if(UpnpOpenHttpGet( url_str_a, &Handle_a,&contentType_a,&contentL=
ength_a,&httpStatus_a, timeout_a ) =3D=3D UPNP_E_SUCCESS)
{ =20
ReadBytes =3D contentLength_a/sizeOfBuffer ;
=20
while(i<=3DReadBytes)
{ =20
memset(buf_a, 0, sizeOfBuffer); =20
retVal =3D UpnpReadHttpGet(Handle_a,buf_a,&sizeOfBuffer,t=
imeout_a);
if ( retVal =3D=3D UPNP_E_SUCCESS)
{
printf("UpnpReadHttpGet is successful\n");
=20
}
else
{
printf("READ ERROR\n");
printf("retVal =3D %d\n",retVal);
break;
}
=20
}
}
=20
=20
}
return 0;
}
I have a printf in membuffer_set_size() for the alloc_len.=20
int
membuffer_set_size( INOUT membuffer * m,
IN size_t new_length )
{
size_t diff;
size_t alloc_len;
char *temp_buf;
if( new_length >=3D m->length ) // increase length
{
// need more mem?
if( new_length <=3D m->capacity ) {
return 0; // have enough mem; done
}
diff =3D new_length - m->length;
alloc_len =3D MAXVAL( m->size_inc, diff ) + m->capacity;
} else // decrease length
{
assert( new_length <=3D m->length );
// if diff is 0..m->size_inc, don't free
if( ( m->capacity - new_length ) <=3D m->size_inc ) {
return 0;
}
alloc_len =3D new_length + m->size_inc;
}
assert( alloc_len >=3D new_length );
printf("alloc-len =3D %ld\n",alloc_len); ////////////Printf added
temp_buf =3D realloc( m->buf, alloc_len + 1 ); //LEAK_FIX_MK
if( temp_buf =3D=3D NULL ) {
// try smaller size
alloc_len =3D new_length;
temp_buf =3D realloc( m->buf, alloc_len + 1 ); //LEAK_FIX_MK
if( temp_buf =3D=3D NULL ) {
return UPNP_E_OUTOF_MEMORY;
}
}
// save
m->buf =3D temp_buf;
m->capacity =3D alloc_len;
return 0;
}
=
=20
When I have run the test application. alloc_len is getting incremented in=
each iteration it can be seen in the log.
Log:
.....
alloc-len =3D 20304146
alloc-len =3D 20306194
alloc-len =3D 20308242
alloc-len =3D 20310290
alloc-len =3D 20312338
alloc-len =3D 20314386
....
alloc-len =3D 22364434
alloc-len =3D 22366482
alloc-len =3D 22368530
alloc-len =3D 22370578
alloc-len =3D 22372626
alloc-len =3D 22374674
alloc-len =3D 22376722
alloc-len =3D 22378770
alloc-len =3D 22380818
alloc-len =3D 22382866
....
Since memory is not getting freed, When I tried to run the same applicati=
on on my platform, I m getting an chrash.
oom-killer: gfp_mask=3D0x201d2, order=3D0
Call trace:
[<8444244e>] out_of_memory+0x14e/0x200
[<84444706>] __alloc_pages+0x306/0x340
[<844469f4>] __do_page_cache_readahead+0x114/0x360
[<8447ca32>] sys_select+0x312/0x4e0
[<84535b74>] memset+0x0/0x4c
[<84440f92>] filemap_nopage+0x112/0x4e0
[<8443d260>] find_get_page+0x0/0xc0
[<8444dcc6>] __handle_mm_fault+0xc6/0xa20
[<84412fc2>] do_page_fault+0x102/0x3e0
[<845468da>] tty_ldisc_deref+0x7a/0xe0
[<84548e06>] tty_write+0xa6/0x280
[<84462f24>] vfs_write+0xc4/0x180
[<844638f8>] sys_write+0x38/0x80
[<84405068>] ret_from_exception+0x0/0x8
[<84405000>] tlb_miss_load+0x0/0x4
Mem-info:
DMA per-cpu:
cpu 0 hot: high 42, batch 7 used:6
cpu 0 cold: high 14, batch 3 used:2
DMA32 per-cpu: empty
Normal per-cpu: empty
HighMem per-cpu: empty
Free pages: 1276kB (0kB HighMem)
Active:21480 inactive:75 dirty:0 writeback:0 unstable:0 free:319 slab:438=
mapped:21488 pagetables:37
DMA free:1276kB min:1280kB low:1600kB high:1920kB active:85920kB inactive=
:300kB present:102400kB pages_scanned:96633 all_unreclaimable? yes
lowmem_reserve[]: 0 0 0 0
DMA32 free:0kB min:0kB low:0kB high:0kB active:0kB inactive:0kB present:0=
kB pages_scanned:0 all_unreclaimable? no
lowmem_reserve[]: 0 0 0 0
Normal free:0kB min:0kB low:0kB high:0kB active:0kB inactive:0kB present:=
0kB pages_scanned:0 all_unreclaimable? no
lowmem_reserve[]: 0 0 0 0
HighMem free:0kB min:128kB low:128kB high:128kB active:0kB inactive:0kB p=
resent:0kB pages_scanned:0 all_unreclaimable? no
lowmem_reserve[]: 0 0 0 0
DMA: 1*4kB 1*8kB 1*16kB 1*32kB 1*64kB 1*128kB 0*256kB 0*512kB 1*1024kB 0*=
2048kB 0*4096kB =3D 1276kB
DMA32: empty
Normal: empty
HighMem: empty
Swap cache: add 0, delete 0, find 0/0, race 0+0
Free swap =3D 0kB
Total swap =3D 0kB
Free swap: 0kB
25600 pages of RAM
2504 reserved pages
8 pages shared
0 pages swap cached
Out of Memory: Kill process 602 (test-try-3.out) score 1387 and children.
Out of memory: Killed process 602 (test-try-3.out).
Killed
Any help will be appriciated.
Regards,
Sangita
=20
---------------------------------
Unlimited freedom, unlimited storage. Get it now
--0-489124388-1204866472=:98513
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Hi All,<br><br>I am using http client of libupnp-1.4.6.<br>Note : Linux v=
ersion which I am using is fedora core 6.<br><br>When I tried to read the=
file from httpd server with test application. <br><br>Test Applica=
tion:<br><br>#include<stdio.h><br>#include<upnp.h><br><br>int=
main(int argc,char * argv[])<br>{<br> char *url_str_a =
=3D "http://localhost/filename.mts";<br> void * Handle_=
a ;<br> char contentType_a ;<br> int =
contentLength_a ;<br> int httpStatus_a ;<br>  =
; int timeout_a =3D 1;<br> char *buf_a =3D (char =
*) malloc(2048);<br> unsigned int sizeOfBuffer =3D 2048=
,ReadRemainingBytes =3D 0;<br> int ReadBytes =3D0 ;<br=
> int retVal =3D 0;<br> &n=
bsp; if(UPNP_E_SUCCESS =3D=3D UpnpInit(NULL,80))<br> &n=
bsp;{<br>
if(UpnpOpenHttpGet( url_str_a, &Handle_a,&contentType_a,&a=
mp;contentLength_a,&httpStatus_a, timeout_a ) =3D=3D UPNP_E_SUCCESS)<=
br> { <br> &n=
bsp; ReadBytes =3D contentLen=
gth_a/sizeOfBuffer ;<br>  =
; <br> whil=
e(i<=3DReadBytes)<br>  =
; { <br> &nb=
sp; memset(buf_a, 0, sizeOfBuffer); &=
nbsp; <br>  =
; retVal =3D
UpnpReadHttpGet(Handle_a,buf_a,&sizeOfBuffer,timeout_a);<br> &n=
bsp; &nb=
sp; &nbs=
p; if ( retVal =3D=3D UPNP_E_SUCCESS)<br>&n=
bsp;  =
;{<br> &nbs=
p; printf("UpnpReadHttpGet is succes=
sful\n");<br> &nb=
sp; <br> &n=
bsp; }<br> &=
nbsp; else<br> &n=
bsp; {<br> &=
nbsp; prin=
tf("READ
ERROR\n");<br> &nbs=
p;  =
; =
printf("retVal =3D %d\n",retVal);<br> =
; &n=
bsp; break;<br> &n=
bsp; }<br> =
<br> =
}<br> }<br>  =
; <br>  =
; <br> }<br><br> &=
nbsp;return 0;<br>}<br><br>I have a printf in membuffer_set_size() for&nb=
sp; the alloc_len. <br><br>int<br>membuffer_set_size( INOUT membuffer *
m,<br> =
IN size_t new_length )<b=
r>{<br> size_t diff;<br> size_t alloc=
_len;<br> char *temp_buf;<br><br> if(=
new_length >=3D m->length ) // increase length<br>&nbs=
p; {<br> // need mo=
re mem?<br> if( new_length <=
=3D m->capacity ) {<br>  =
; return 0; &n=
bsp; // have enough mem; done<br> &nbs=
p; }<br><br> diff =3D=
new_length - m->length;<br> =
alloc_len =3D MAXVAL( m->size_inc, diff ) + m->capacity;<br> =
}
else &n=
bsp; // decrease le=
ngth<br> {<br>  =
; assert( new_length <=3D m->length );<br><br> &nb=
sp; // if diff is 0..m->size_inc, don't free<br>&nbs=
p; if( ( m->capacity - new_length =
) <=3D m->size_inc ) {<br>  =
; return 0;<br> &nbs=
p; }<br><br> alloc_len =3D=
new_length + m->size_inc;<br> }<br><br> =
assert( alloc_len >=3D new_length );<br>  =
; printf("alloc-len =3D %ld\n",alloc_len); ////////////=
Printf added<br> temp_buf =3D realloc( m->buf, alloc=
_len + 1 );
//LEAK_FIX_MK<br><br> if( temp_buf =3D=3D =
NULL ) {<br> // try smaller siz=
e<br> alloc_len =3D new_length;=
<br> temp_buf =3D realloc( m-&g=
t;buf, alloc_len + 1 ); //LEAK_FIX_MK<br> &n=
bsp; if( temp_buf =3D=3D NULL ) {<br> =
return UPNP_=
E_OUTOF_MEMORY;<br> }<br> =
}<br> // save<br> m->=
buf =3D temp_buf;<br> m->capacity =3D alloc_len;<br>=
return
0;<br>}<br> &=
nbsp; &n=
bsp; &nb=
sp; &nbs=
p;  =
; =
<br><br><br><br>When I have run the =
test application. alloc_len is getting incremented in each iteration it c=
an be seen in the log.<br><br>Log:<br><br>....<br>alloc-len =3D 20304146<=
br>alloc-len =3D 20306194<br>alloc-len =3D 20308242<br>alloc-len =3D 2031=
0290<br>alloc-len =3D 20312338<br>alloc-len =3D 20314386<br>...<br>alloc-=
len =3D 22364434<br>alloc-len =3D 22366482<br>alloc-len =3D 22368530<br>a=
lloc-len =3D 22370578<br>alloc-len =3D 22372626<br>alloc-len =3D 22374674=
<br>alloc-len =3D 22376722<br>alloc-len =3D 22378770<br>alloc-len =3D
22380818<br>alloc-len =3D 22382866<br>...<br><br><br>Since memory is not=
getting freed, When I tried to run the same application on my platform, =
I m getting an chrash.<br><br><br><br>oom-killer: gfp_mask=3D0x201d2, ord=
er=3D0<br><br>Call trace:<br>[<8444244e>] out_of_memory+0x14e/0x200=
<br>[<84444706>] __alloc_pages+0x306/0x340<br>[<844469f4>] __=
do_page_cache_readahead+0x114/0x360<br>[<8447ca32>] sys_select+0x31=
2/0x4e0<br>[<84535b74>] memset+0x0/0x4c<br>[<84440f92>] filem=
ap_nopage+0x112/0x4e0<br>[<8443d260>] find_get_page+0x0/0xc0<br>[&l=
t;8444dcc6>] __handle_mm_fault+0xc6/0xa20<br>[<84412fc2>] do_pag=
e_fault+0x102/0x3e0<br>[<845468da>] tty_ldisc_deref+0x7a/0xe0<br>[&=
lt;84548e06>] tty_write+0xa6/0x280<br>[<84462f24>] vfs_write+0xc=
4/0x180<br>[<844638f8>] sys_write+0x38/0x80<br>[<84405068>] r=
et_from_exception+0x0/0x8<br>[<84405000>] tlb_miss_load+0x0/0x4<br>=
<br>Mem-info:<br>DMA per-cpu:<br>cpu 0 hot:
high 42, batch 7 used:6<br>cpu 0 cold: high 14, batch 3 used:2<br>DMA32 =
per-cpu: empty<br>Normal per-cpu: empty<br>HighMem per-cpu: empty<br>Free=
pages: 1276kB (0kB HighMem)<br=
>Active:21480 inactive:75 dirty:0 writeback:0 unstable:0 free:319 slab:43=
8 mapped:21488 pagetables:37<br>DMA free:1276kB min:1280kB low:1600kB hig=
h:1920kB active:85920kB inactive:300kB present:102400kB pages_scanned:966=
33 all_unreclaimable? yes<br>lowmem_reserve[]: 0 0 0 0<br>DMA32 free:0kB =
min:0kB low:0kB high:0kB active:0kB inactive:0kB present:0kB pages_scanne=
d:0 all_unreclaimable? no<br>lowmem_reserve[]: 0 0 0 0<br>Normal free:0kB=
min:0kB low:0kB high:0kB active:0kB inactive:0kB present:0kB pages_scann=
ed:0 all_unreclaimable? no<br>lowmem_reserve[]: 0 0 0 0<br>HighMem free:0=
kB min:128kB low:128kB high:128kB active:0kB inactive:0kB present:0kB pag=
es_scanned:0 all_unreclaimable? no<br>lowmem_reserve[]: 0 0 0 0<br>DMA: 1=
*4kB 1*8kB 1*16kB 1*32kB 1*64kB 1*128kB
0*256kB 0*512kB 1*1024kB 0*2048kB 0*4096kB =3D 1276kB<br>DMA32: empty<br=
>Normal: empty<br>HighMem: empty<br>Swap cache: add 0, delete 0, find 0/0=
, race 0+0<br>Free swap =3D 0kB<br>Total swap =3D 0kB<br>Free swap:=
0kB<br=
>25600 pages of RAM<br>2504 reserved pages<br>8 pages shared<br>0 pages s=
wap cached<br>Out of Memory: Kill process 602 (test-try-3.out) score 1387=
and children.<br>Out of memory: Killed process 602 (test-try-3.out).<br>=
Killed<br><br><br><br>Any help will be appriciated.<br><br>Regards,<br>Sa=
ngita<br><br><br><br><br><br><br><br><br><br><br><br><br><p> 
<!--2--><hr size=3D1></hr> Unlimited freedom, unlimited storage. <a=
href=3D"http://in.rd.yahoo.com/tagline_mail_2/*http://help.yahoo.com/l/i=
n/yahoo/mail/yahoomail/tools/tools-08.html/">Get it now</a>
--0-489124388-1204866472=:98513--
--===============0501821582==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
--===============0501821582==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
UPnP-SDK-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/upnp-sdk-discuss
--===============0501821582==--