[Asterisk-cvs] libpri pri_facility.c,1.5,1.6 testprilib.c,1.5,1.6

mattf at lists.digium.com mattf at lists.digium.com
Thu Mar 10 14:40:57 CST 2005


Update of /usr/cvsroot/libpri
In directory mongoose.digium.com:/tmp/cvs-serv7820

Modified Files:
	pri_facility.c testprilib.c 
Log Message:
Fixed some free() bugs in the APDU code.  


Index: pri_facility.c
===================================================================
RCS file: /usr/cvsroot/libpri/pri_facility.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- pri_facility.c	2 Mar 2005 16:03:22 -0000	1.5
+++ pri_facility.c	10 Mar 2005 20:37:16 -0000	1.6
@@ -801,16 +801,16 @@
 		case SS_CNID_CALLINGNAME:
 			if (pri->debug & PRI_DEBUG_APDU)
 				pri_message("  Handle Name display operation\n");
-			switch (comp->type & PRI_DEBUG_APDU) {
-			case ROSE_NAME_PRESENTATION_ALLOWED_SIMPLE:
-				memcpy(call->callername, comp->data, comp->len);
-				call->callername[comp->len] = 0;
-				if (pri->debug & PRI_DEBUG_APDU)
-				  pri_message("    Received caller name '%s'\n", call->callername);
-				return 0;
-			default:
-				pri_message("Do not handle argument of type 0x%X\n", comp->type);
-				return -1;
+			switch (comp->type) {
+				case ROSE_NAME_PRESENTATION_ALLOWED_SIMPLE:
+					memcpy(call->callername, comp->data, comp->len);
+					call->callername[comp->len] = 0;
+					if (pri->debug & PRI_DEBUG_APDU)
+					  pri_message("    Received caller name '%s'\n", call->callername);
+					return 0;
+				default:
+					pri_message("Do not handle argument of type 0x%X\n", comp->type);
+					return -1;
 			}
 			break;
 		case ROSE_DIVERTING_LEG_INFORMATION2:
@@ -839,9 +839,9 @@
 		return -1;
 
 	new_event = malloc(sizeof(struct apdu_event));
-	memset(new_event, 0, sizeof(struct apdu_event));
 
 	if (new_event) {
+		memset(new_event, 0, sizeof(struct apdu_event));
 		new_event->message = messagetype;
 		new_event->callback = function;
 		new_event->data = data;
@@ -873,8 +873,8 @@
 		while (cur_event) {
 			/* TODO: callbacks, some way of giving return res on status of apdu */
 			free_event = cur_event;
-			free(free_event);
 			cur_event = cur_event->next;
+			free(free_event);
 		}
 		call->apdus = NULL;
 	}

Index: testprilib.c
===================================================================
RCS file: /usr/cvsroot/libpri/testprilib.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- testprilib.c	2 Mar 2005 15:56:11 -0000	1.5
+++ testprilib.c	10 Mar 2005 20:37:16 -0000	1.6
@@ -76,7 +76,6 @@
 	int x;
 	static q931_call *calls[TEST_CALLS];
 	char name[256], num[256], dest[256];
-	struct pri_sr *sr;
 	switch(e->gen.e) {
 	case PRI_EVENT_DCHAN_UP:
 		printf("Network is up.  Sending blast of calls!\n");
@@ -89,15 +88,18 @@
 				continue;
 			}
 #if 0
-			sr = pri_sr_new();
-			pri_sr_set_channel(sr, x+1, 0, 0);
-			pri_sr_set_bearer(sr, 0, PRI_LAYER_1_ULAW);
-			pri_sr_set_called(sr, dest, PRI_NATIONAL_ISDN, 1);
-			pri_sr_set_caller(sr, num, name, PRI_NATIONAL_ISDN, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN);
-			pri_sr_set_redirecting(sr, num, PRI_NATIONAL_ISDN, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, PRI_REDIR_UNCONDITIONAL);
-			if (pri_setup(pri, calls[x], sr))
-				perror("pri_setup");
-			pri_sr_free(sr);
+			{
+				struct pri_sr *sr;
+				sr = pri_sr_new();
+				pri_sr_set_channel(sr, x+1, 0, 0);
+				pri_sr_set_bearer(sr, 0, PRI_LAYER_1_ULAW);
+				pri_sr_set_called(sr, dest, PRI_NATIONAL_ISDN, 1);
+				pri_sr_set_caller(sr, num, name, PRI_NATIONAL_ISDN, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN);
+				pri_sr_set_redirecting(sr, num, PRI_NATIONAL_ISDN, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, PRI_REDIR_UNCONDITIONAL);
+				if (pri_setup(pri, calls[x], sr))
+					perror("pri_setup");
+				pri_sr_free(sr);
+			}
 #else
 			if (pri_call(pri, calls[x], PRI_TRANS_CAP_DIGITAL, x + 1, 1, 1, num, 
 				PRI_NATIONAL_ISDN, name, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN,
@@ -113,6 +115,10 @@
 		q931_facility(pri, e->ringing.call);
 		pri_answer(pri, e->ringing.call, e->ringing.channel, 0);
 		break;
+	case PRI_EVENT_HANGUP_REQ:
+		printf("PRI 1: %s (%d)\n", pri_event2str(e->gen.e), e->gen.e);
+		pri_hangup(pri, e->hangup.call, e->hangup.cause);
+		break;
 	default:
 		printf("PRI 1: %s (%d)\n", pri_event2str(e->gen.e), e->gen.e);
 	}
@@ -127,6 +133,14 @@
 		pri_proceeding(pri, e->ring.call, e->ring.channel, 0);
 		pri_acknowledge(pri, e->ring.call, e->ring.channel, 0);
 		break;
+	case PRI_EVENT_ANSWER:
+		printf("PRI 2: %s (%d)\n", pri_event2str(e->gen.e), e->gen.e);
+		pri_hangup(pri, e->answer.call, PRI_CAUSE_NORMAL_UNSPECIFIED);
+		break;
+	case PRI_EVENT_HANGUP:
+		printf("PRI 2: %s (%d)\n", pri_event2str(e->gen.e), e->gen.e);
+		pri_hangup(pri, e->hangup.call, e->hangup.cause);
+		break;
 	case PRI_EVENT_DCHAN_UP:
 	default:
 		printf("PRI 2: %s (%d)\n", pri_event2str(e->gen.e), e->gen.e);
@@ -195,7 +209,7 @@
 	fd_set fds;
 	int res;
 	for(;;) {
-		if (next == pri_schedule_next(pri)) {
+		if ((next = pri_schedule_next(pri))) {
 			gettimeofday(&tv, NULL);
 			tv.tv_sec = next->tv_sec - tv.tv_sec;
 			tv.tv_usec = next->tv_usec - tv.tv_usec;




More information about the svn-commits mailing list