speechd-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Corrected some memory leacs in src/tests/run_test.c


From: Rui Batista
Subject: [PATCH] Corrected some memory leacs in src/tests/run_test.c
Date: Tue, 16 Feb 2010 16:04:46 +0000

In send_data a reply buffer was being alocated and never freeed, even if not 
needed. The reply buffers alocated in send_data should be freeed in main too, 
like the line buffer. This commit address also these changes.
---
 src/tests/run_test.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/tests/run_test.c b/src/tests/run_test.c
index 15a00c0..dfb0b49 100644
--- a/src/tests/run_test.c
+++ b/src/tests/run_test.c
@@ -61,14 +61,14 @@ send_data(int fd, char *message, int wfr)
        char *reply;
        int bytes;
 
-       /* TODO: 1000?! */
-       reply = (char*) malloc(sizeof(char) * 1000);
    
        /* write message to the socket */
        write(fd, message, strlen(message));
 
        /* read reply to the buffer */
        if (wfr == 1){
+               /* TODO: 1000?! */
+               reply = (char*) malloc(sizeof(char) * 1000);
                bytes = read(fd, reply, 1000);
                /* print server reply to as a string */
                reply[bytes] = 0; 
@@ -163,7 +163,6 @@ main(int argc, char* argv[])
     printf("==================\n\n");
        
     line = malloc(1024 * sizeof(char));
-    reply = malloc(4096 * sizeof(char));
 
     sockk = init("run_test","user_test");
     if(sockk == 0) FATAL("Can't connect to Speech Dispatcher");
@@ -196,6 +195,7 @@ main(int argc, char* argv[])
             fflush(NULL);
             reply = send_data(sockk, command, 1);
             printf("     < %s", reply);
+            free(reply);
             fflush(NULL);
             continue;
         }
@@ -203,6 +203,7 @@ main(int argc, char* argv[])
         if(line[0] == '.'){
             reply = send_data(sockk, "\r\n.\r\n", 1);
             printf("       < %s", reply);
+            free(reply);
             continue;
         }
 
@@ -254,6 +255,7 @@ main(int argc, char* argv[])
 
 
     close(sockk);
+    free(line);
 
     printf("\n==================\n");
     printf("End of the test.\n");
-- 
1.6.3.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]