2 Replies - 210 Views - Last Post: 05 July 2013 - 10:56 AM Rate Topic: -----

#1 exgenome  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 06-February 09

segmentation fault on calling malloc

Posted 05 July 2013 - 09:52 AM

Hi guys,
M working on a code to query google and then process the results. The code is bit long and it seems to create a segmentation fault on calling malloc at line 905. however the call to malloc is successful previously cant figure out why. sorry the code is bit lame as m nt tht good in c. hv attached my code in file.
thanks :)/>

Is This A Good Question/Topic? 0
  • +

Replies To: segmentation fault on calling malloc

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 3848
  • View blog
  • Posts: 11,775
  • Joined: 25-December 09

Re: segmentation fault on calling malloc

Posted 05 July 2013 - 10:05 AM

I would first suggest you increase your compiler warning level and fix all the warnings that the compiler generates.

Quote

main.c|18|error: "BUFSIZ" redefined|
/usr/include/stdio.h|128|note: this is the location of the previous definition|
main.c|24|warning: no previous declaration for ‘strmatch’ [-Wmissing-declarations]|
main.c||In function ‘strmatch’:|
main.c|28|warning: declaration of ‘a’ shadows a global declaration [-Wshadow]|
main.c|19|warning: shadowed declaration is here [-Wshadow]|
main.c|49|warning: no previous declaration for ‘locate_atrib’ [-Wmissing-declarations]|
main.c||In function ‘locate_atrib’:|
main.c|66|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
main.c|72|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
main.c|78|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
main.c|84|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
main.c|51|warning: unused variable ‘search1’ [-Wunused-variable]|
main.c|51|warning: unused variable ‘search’ [-Wunused-variable]|
main.c|92|warning: no previous declaration for ‘atrib_val’ [-Wmissing-declarations]|
main.c||In function ‘atrib_val’:|
main.c|92|warning: declaration of ‘a’ shadows a global declaration [-Wshadow]|
main.c|19|warning: shadowed declaration is here [-Wshadow]|
main.c|122|warning: function returns address of local variable [enabled by default]|
main.c|142|warning: function returns address of local variable [enabled by default]|
main.c|145|warning: function returns address of local variable [enabled by default]|
main.c|94|warning: unused variable ‘search’ [-Wunused-variable]|
main.c|149|warning: no previous declaration for ‘locate_tag’ [-Wmissing-declarations]|
main.c|192|warning: no previous declaration for ‘tag_val’ [-Wmissing-declarations]|
main.c||In function ‘tag_val’:|
main.c|192|warning: declaration of ‘a’ shadows a global declaration [-Wshadow]|
main.c|19|warning: shadowed declaration is here [-Wshadow]|
main.c|207|warning: function returns address of local variable [enabled by default]|
main.c|211|warning: function returns address of local variable [enabled by default]|
main.c|195|warning: unused variable ‘val1’ [-Wunused-variable]|
main.c|194|warning: unused variable ‘j’ [-Wunused-variable]|
main.c|234|warning: no previous declaration for ‘create_node’ [-Wmissing-declarations]|
main.c|243|warning: no previous declaration for ‘insert_end’ [-Wmissing-declarations]|
main.c|273|warning: no previous declaration for ‘remove_end’ [-Wmissing-declarations]|
main.c|287|warning: no previous declaration for ‘trav’ [-Wmissing-declarations]|
main.c|302|warning: no previous declaration for ‘remove_all’ [-Wmissing-declarations]|
main.c||In function ‘remove_all’:|
main.c|304|warning: unused variable ‘temp’ [-Wunused-variable]|
main.c|326|warning: no previous declaration for ‘cont_data’ [-Wmissing-declarations]|
main.c|511|warning: "/*" within comment [-Wcomment]|
main.c|550|warning: no previous declaration for ‘strmatch_l’ [-Wmissing-declarations]|
main.c||In function ‘strmatch_l’:|
main.c|557|warning: declaration of ‘a’ shadows a global declaration [-Wshadow]|
main.c|19|warning: shadowed declaration is here [-Wshadow]|
main.c|579|warning: no previous declaration for ‘locate_atrib_l’ [-Wmissing-declarations]|
main.c||In function ‘locate_atrib_l’:|
main.c|595|warning: unused variable ‘tag_e’ [-Wunused-variable]|
main.c|595|warning: unused variable ‘tag_s’ [-Wunused-variable]|
main.c|585|warning: unused variable ‘j’ [-Wunused-variable]|
main.c|636|warning: no previous declaration for ‘atrib_val_l’ [-Wmissing-declarations]|
main.c||In function ‘atrib_val_l’:|
main.c|639|error: return makes pointer from integer without a cast|
main.c|670|warning: function returns address of local variable [enabled by default]|
main.c|674|warning: no previous declaration for ‘locate_tag_l’ [-Wmissing-declarations]|
main.c||In function ‘locate_tag_l’:|
main.c|690|warning: declaration of ‘a’ shadows a global declaration [-Wshadow]|
main.c|19|warning: shadowed declaration is here [-Wshadow]|
main.c|728|warning: no previous declaration for ‘tag_val_l’ [-Wmissing-declarations]|
main.c||In function ‘tag_val_l’:|
main.c|728|warning: declaration of ‘a’ shadows a global declaration [-Wshadow]|
main.c|19|warning: shadowed declaration is here [-Wshadow]|
main.c|735|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
main.c|730|warning: unused variable ‘j’ [-Wunused-variable]|
main.c|751|warning: no previous declaration for ‘get_login_form’ [-Wmissing-declarations]|
main.c||In function ‘get_login_form’:|
main.c|792|warning: declaration of ‘a’ shadows a global declaration [-Wshadow]|
main.c|19|warning: shadowed declaration is here [-Wshadow]|
main.c|756|warning: unused variable ‘ex’ [-Wunused-variable]|
main.c|754|warning: unused variable ‘count’ [-Wunused-variable]|
main.c|753|warning: unused variable ‘i’ [-Wunused-variable]|
main.c|853|warning: no previous declaration for ‘build_query’ [-Wmissing-declarations]|
main.c|871|warning: no previous declaration for ‘url_process’ [-Wmissing-declarations]|
main.c||In function ‘url_process’:|
main.c|873|warning: unused variable ‘end’ [-Wunused-variable]|
main.c|894|warning: no previous declaration for ‘build_query_fr_target’ [-Wmissing-declarations]|
main.c|911|warning: no previous declaration for ‘build_login_query’ [-Wmissing-declarations]|
main.c||In function ‘build_login_query’:|
main.c|916|warning: unused variable ‘getpage’ [-Wunused-variable]|
main.c|915|warning: unused variable ‘tpl’ [-Wunused-variable]|
main.c|940|warning: no previous declaration for ‘send_receive’ [-Wmissing-declarations]|
main.c||In function ‘send_receive’:|
main.c|978|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
main.c||In function ‘main’:|
main.c|1080|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
main.c|1114|warning: declaration of ‘a’ shadows a global declaration [-Wshadow]|
main.c|19|warning: shadowed declaration is here [-Wshadow]|
main.c|1117|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
main.c|1129|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
main.c|1070|warning: variable ‘check’ set but not used [-Wunused-but-set-variable]|
main.c|1222|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
main.c|1173|warning: unused variable ‘check’ [-Wunused-variable]|
main.c|1024|warning: unused variable ‘pa’ [-Wunused-variable]|
main.c|1024|warning: variable ‘page’ set but not used [-Wunused-but-set-variable]|
main.c||In function ‘get_ip’:|
main.c|1352|error: implicit declaration of function ‘herror’ [-Wimplicit-function-declaration]|
main.c||In function ‘send_receive’:|
main.c|1008|warning: control reaches end of non-void function [-Wreturn-type]|
main.c||In function ‘locate_tag_l’:|
main.c|724|warning: control reaches end of non-void function [-Wreturn-type]|
main.c||In function ‘locate_tag’:|
main.c|190|warning: control reaches end of non-void function [-Wreturn-type]|
||=== Build finished: 4 errors, 78 warnings ===|


Next are you sure all your arrays being used in that malloc are properly terminated C-strings?

Also don't cast the return value from malloc, and do you really need the global varaibles?

Jim

This post has been edited by jimblumberg: 05 July 2013 - 10:07 AM

Was This Post Helpful? 1
  • +
  • -

#3 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3183
  • View blog
  • Posts: 9,652
  • Joined: 05-May 12

Re: segmentation fault on calling malloc

Posted 05 July 2013 - 10:56 AM

What exactly is that code supposed to do? I was just scanning through it, and it seems to be that what it is doing is that it is trying to find all login pages according to Google, and then using the URLs to those login pages, it attempts to login to the various sites given a particular user name and password.

In other words, it looks like a hacking tool.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1