Your browser does not support our blog javascript

readline

search for more blogs here

 
Home - Take this blog! - Get your Author's Pass Here - Submit Comments Below

Memory problem using malloc and free

Posted by ~Ray @ 2007-12-15 15:47:33


-bash-3.1$ ./shell% hi hterehiLooking in /usr/lib/qt-3.3/bin trying to find hiLooking in /usr/place/bin trying to find hiLooking in /usr/local/bin trying to find hiLooking in /bin trying to sight hiLooking in /usr/bin trying to find hiError hi was not open htereLooking in /usr/lib/qt-3.3/bin trying to sight htereLooking in /usr/place/bin trying to sight htere*** glibc detected *** ./shell: remove(): invalid next size (fast): 0x086f5010 ***======= Backtrace: =========/lib/libc so.6[0x4179df7d]/lib/libc so.6(cfree+0x90)[0x417a15d0]./bomb[0x8048826]./bomb[0x804894a]/lib/libc so.6(__libc_go away_main+0xdc)[0x4174ddec]./shell[0x80485b1]======= Memory map: ======== [stack]Aborted burn *lookupPath(char *name){ int counter = 0;while (dirs[answer] != NULL && answer < MAXPATHS){ printf("Looking in %s trying to find %s\n" dirs[counter] label);if(label != NULL && label[0] == '/'){if( access(label. X_OK) == 0 )return label;}else { char* pName = (char*) malloc (strlen(label)+strlen(dirs[counter]+strlen("/")+1)); sprintf(pName. "%s/%s" dirs[answer] name); if(access(pName. X_OK) == 0) return pName; remove(pName);}counter++;}printf("Error %s was not found.\n" name);go NULL;} I be to be freeing the memory of pName but i'm returning the pointer. I realize that i only remove the memory if pName isn't used but how do i remove it in the case that it is used? In case i'm do by about where the error is the be of my label is below edit: removed full label. Thanks for looking! I be to be freeing the memory of pName but i'm returning the pointer. I realize that i only free the memory if pName isn't used but how do i free it in the case that it is used? Whoever called lookupPath() is going to undergo to free it. I don't see anything wrong with the way you use memory in the lookupPath() answer so the memory corruption must be happening somewhere else. Or you are double-freeing a pointer or freeing a bad pointer. alter: Actually I see the problem.[ADVERTHERE]Related article:
http://cboard.cprogramming.com/showthread.php?t=94891


0 Comments:


No comments have been posted yet!

From:   Website:
Subject:   Code:
Message:


   

 


 

 

 





blogs - aa blogs - air force blogs - aquarius blogs - aries blogs - army blogs - arts blogs - baby blogs - blogs 4 men - blogs 4 women - cancer blogs - capricorn blogs - career change blogs - choice blogs - christmas blogs - cigar blogs - cigarette blogs - cig blogs - coast guard blogs - coffee bean blogs - college baseball blogs - college basketball blogs - college football blogs - colleges blogs - computer blogs - create blogs - dating blogs - elvis blogs - email chat blogs - email pal blogs - enhancement blogs - fall blogs - fha blogs - freedom blogs - friendly blogs - funny blogs - gambler blogs - gemini blogs - her blog - his blog - hockey blogs - join blogs - javas blogs - kid safe blogs - leo blogs - libra blogs - apartments blogs - coffees blogs - horoscopes blogs - life advice blogs - lover blogs - marine blogs - married blogs - military blogs - misc blogs - more money blogs - mortgage blogs - move blogs - movies blogs - musical blogs - navy blogs - new in town blogs - obscure blogs - online date blogs - online game blogs - over 30 blogs - over 40 blogs - over 50 blogs - over 60 blogs - over 70 blogs - over 80 blogs - over 90 blogs - password blogs - pc blogs - mortgages blogs - peoples blogs - pictures blogs - pipe blogs - pisces blogs - poems blogs - poker blogs - police blogs - political blogs radio blogs - read blogs - recreational vehicle blogs - relocation blogs - reserve blogs - rv blogs - safe blogs - scorpio blogs - singles blogs - smokers blogs - smoker blogs - state blogs - state college blogs - taurus blogs - teen advice blogs - teenager blogs - tobacco blogs - tv blogs - vacation blogs - veteran blogs - virgo blogs - virtual blogs - weekly blogs - wingman blogs - word blogs - words blogs - writer blogs - poetry blogs - prescription blogs - sagittarius blogs - straight blogs - summer blogs - gi blogs - hooka blogs - penis enlargement blogs - vfw blogs - casinos blogs - casino blogs - web hosting blogs - hosting blogs - auto blogs - truck blogs - van blogs - suv blogs - 4 wheel blogs - harley blogs - flu blogs - diet blogs - pistols blogs - teenage blogs - lpga blogs - burnable blogs - new tunes blogs - coaching blogs - treasures blogs - trades blogs - nutty blogs - skate blogs - play 21 blogs - weather blogs - poker players - golf blogs - american blogs - football blogs - baseball blogs - hockey blogs - basketball blogs - soccer blogs - cooking blogs - recipe blogs - space blogs - 3d games blogs - barbecue blogs




blogs home