comparison libpurple/dnssrv.c @ 32203:451242c455ca

dnssrv: Proper memory management here, which stops random crashes elsewhere. 'query' is owned by the query_data, so must not be freed.
author Paul Aurich <paul@darkrain42.org>
date Sun, 17 Jul 2011 20:08:13 +0000
parents 4739488955a7
children 9821c19360b8
comparison
equal deleted inserted replaced
32202:4739488955a7 32203:451242c455ca
746 746
747 #ifndef _WIN32 747 #ifndef _WIN32
748 if(pipe(in) || pipe(out)) { 748 if(pipe(in) || pipe(out)) {
749 purple_debug_error("dnssrv", "Could not create pipe\n"); 749 purple_debug_error("dnssrv", "Could not create pipe\n");
750 g_free(query); 750 g_free(query);
751 g_free(query_data);
751 cb(NULL, 0, extradata); 752 cb(NULL, 0, extradata);
752 return NULL; 753 return NULL;
753 } 754 }
754 755
755 pid = fork(); 756 pid = fork();
756 if (pid == -1) { 757 if (pid == -1) {
757 purple_debug_error("dnssrv", "Could not create process!\n"); 758 purple_debug_error("dnssrv", "Could not create process!\n");
759 g_free(query);
760 g_free(query_data);
758 cb(NULL, 0, extradata); 761 cb(NULL, 0, extradata);
759 g_free(query);
760 return NULL; 762 return NULL;
761 } 763 }
762 764
763 /* Child */ 765 /* Child */
764 if (pid == 0) 766 if (pid == 0)
765 { 767 {
766 g_free(query); 768 g_free(query);
769 g_free(query_data);
767 770
768 close(out[0]); 771 close(out[0]);
769 close(in[1]); 772 close(in[1]);
770 resolve(in[0], out[1]); 773 resolve(in[0], out[1]);
771 /* resolve() does not return */ 774 /* resolve() does not return */
783 786
784 query_data->pid = pid; 787 query_data->pid = pid;
785 query_data->fd_out = out[0]; 788 query_data->fd_out = out[0];
786 query_data->fd_in = in[1]; 789 query_data->fd_in = in[1];
787 query_data->handle = purple_input_add(out[0], PURPLE_INPUT_READ, resolved, query_data); 790 query_data->handle = purple_input_add(out[0], PURPLE_INPUT_READ, resolved, query_data);
788
789 g_free(query);
790 791
791 return query_data; 792 return query_data;
792 #else 793 #else
793 if (!initialized) { 794 if (!initialized) {
794 MyDnsQuery_UTF8 = (void*) wpurple_find_and_loadproc("dnsapi.dll", "DnsQuery_UTF8"); 795 MyDnsQuery_UTF8 = (void*) wpurple_find_and_loadproc("dnsapi.dll", "DnsQuery_UTF8");
881 882
882 #ifndef _WIN32 883 #ifndef _WIN32
883 if(pipe(in) || pipe(out)) { 884 if(pipe(in) || pipe(out)) {
884 purple_debug_error("dnssrv", "Could not create pipe\n"); 885 purple_debug_error("dnssrv", "Could not create pipe\n");
885 g_free(query); 886 g_free(query);
887 g_free(query_data);
886 cb(NULL, extradata); 888 cb(NULL, extradata);
887 return NULL; 889 return NULL;
888 } 890 }
889 891
890 pid = fork(); 892 pid = fork();
891 if (pid == -1) { 893 if (pid == -1) {
892 purple_debug_error("dnssrv", "Could not create process!\n"); 894 purple_debug_error("dnssrv", "Could not create process!\n");
895 g_free(query);
896 g_free(query_data);
893 cb(NULL, extradata); 897 cb(NULL, extradata);
894 g_free(query);
895 return NULL; 898 return NULL;
896 } 899 }
897 900
898 /* Child */ 901 /* Child */
899 if (pid == 0) 902 if (pid == 0)
900 { 903 {
901 g_free(query); 904 g_free(query);
905 g_free(query_data);
902 906
903 close(out[0]); 907 close(out[0]);
904 close(in[1]); 908 close(in[1]);
905 resolve(in[0], out[1]); 909 resolve(in[0], out[1]);
906 /* resolve() does not return */ 910 /* resolve() does not return */
918 922
919 query_data->pid = pid; 923 query_data->pid = pid;
920 query_data->fd_out = out[0]; 924 query_data->fd_out = out[0];
921 query_data->fd_in = in[1]; 925 query_data->fd_in = in[1];
922 query_data->handle = purple_input_add(out[0], PURPLE_INPUT_READ, resolved, query_data); 926 query_data->handle = purple_input_add(out[0], PURPLE_INPUT_READ, resolved, query_data);
923
924 g_free(query);
925 927
926 return query_data; 928 return query_data;
927 #else 929 #else
928 if (!initialized) { 930 if (!initialized) {
929 MyDnsQuery_UTF8 = (void*) wpurple_find_and_loadproc("dnsapi.dll", "DnsQuery_UTF8"); 931 MyDnsQuery_UTF8 = (void*) wpurple_find_and_loadproc("dnsapi.dll", "DnsQuery_UTF8");