changeset 234:728ff2104991

Fix segmentation fault
author Sebastien Decugis <sdecugis@nict.go.jp>
date Wed, 12 Nov 2008 11:48:03 +0900
parents fa76f88326fd
children e9352025fbcc
files waaad/peer-sctp.c
diffstat 1 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/waaad/peer-sctp.c	Tue Nov 11 16:19:16 2008 +0900
+++ b/waaad/peer-sctp.c	Wed Nov 12 11:48:03 2008 +0900
@@ -1037,17 +1037,18 @@
 		TRACE_DEBUG(INFO, "recvmsg returned %d, errno: %s", ret, strerror(errno));
 		CHECK_FCT_DO(  _peer_events_send(peer, PEVENT_DISCONNECTED, NULL), /* nothing */ );
 		free(*data);
-		return 0;
+		goto out;
 	}
 		
 	if (ret < 0) {
 		TRACE_DEBUG(INFO, "recvmsg returned %d, errno: %s", ret, strerror(errno));
 		free(*data);
-		return ret;
+		goto out;
 	}
 
 	/* we have received new data */
 	*len += ret;
+	ret = -1;
 	
 	/* loop if we have not received a full message yet */
 	if ( (mhdr.msg_flags & MSG_EOR) == 0 ) {
@@ -1058,7 +1059,7 @@
 			sz += sysconf(_SC_PAGESIZE);
 			
 			/* enlarge the buffer to receive more data */
-			CHECK_MALLOC_DO(  *data = realloc(*data, sz),  return -1  );
+			CHECK_MALLOC_DO(  *data = realloc(*data, sz),  goto out );
 		}
 		goto incomplete;
 	}
@@ -1102,7 +1103,7 @@
 				#endif /* DEBUG_SCTP */
 				
 				CHECK_FCT_DO( iret =  _peer_events_send(peer, PEVENT_SND_FAILED, NULL /* could put ssf_error here if useful */), 
-						{  errno = iret; return -1; }  );
+						{  errno = iret; goto out; }  );
 				break;
 			
 			case SCTP_REMOTE_ERROR:
@@ -1121,7 +1122,7 @@
 				#endif /* DEBUG_SCTP */
 				
 				CHECK_FCT_DO( iret =  _peer_events_send(peer, PEVENT_DISCONNECTED, NULL), 
-						{  errno = iret; return -1; }  );
+						{  errno = iret; goto out; }  );
 				break;
 			
 			default:	
@@ -1166,12 +1167,14 @@
 		}
 	}
 	
-	pthread_cleanup_pop(0);
-	
 	/* Okay, we have received a normal message */
 	#ifdef DEBUG_SCTP
 	TRACE_DEBUG(FULL, "Received SCTP packet (%d bytes on stream %hu) from '%s'", *len, *streamid, peer->p_diamid ? peer->p_diamid : "(unknown)");
 	#endif /* DEBUG_SCTP */
 	
-	return *len;
+	ret = *len;
+	
+out:	
+	pthread_cleanup_pop(0);
+	return ret;
 }		
"Welcome to our mercurial repository"