Browse code

b/f: initialize msg_type, be more careful when releasing memory

Stefan Sayer authored on 25/02/2014 12:19:05
Showing 1 changed files
... ...
@@ -58,7 +58,8 @@ sip_msg::sip_msg(const char* msg_buf, int msg_len)
58 58
       content_type(NULL),
59 59
       content_length(NULL),
60 60
       body(),
61
-      local_socket(NULL)
61
+      local_socket(NULL),
62
+      type(SIP_UNKNOWN)
62 63
 {
63 64
     u.request = 0;
64 65
     u.reply   = 0;
... ...
@@ -84,7 +85,8 @@ sip_msg::sip_msg()
84 85
       content_type(NULL),
85 86
       content_length(NULL),
86 87
       body(),
87
-      local_socket(NULL)
88
+      local_socket(NULL),
89
+      type(SIP_UNKNOWN)
88 90
 {
89 91
     u.request = 0;
90 92
     u.reply   = 0;
... ...
@@ -106,10 +108,10 @@ sip_msg::~sip_msg()
106 108
     }
107 109
 
108 110
     if(u.request){
109
-	if(type == SIP_REQUEST){
111
+	if(type == SIP_REQUEST && u.request){
110 112
 	    delete u.request;
111 113
 	}
112
-	else {
114
+	else if(type == SIP_REPLY && u.reply) {
113 115
 	    delete u.reply;
114 116
 	}
115 117
     }