git-rm: honor -n flag.
[git.git] / imap-send.c
index f3cb79b..285ad29 100644 (file)
@@ -924,6 +924,7 @@ imap_open_store( imap_server_conf_t *srvc )
        struct hostent *he;
        struct sockaddr_in addr;
        int s, a[2], preauth;
+       pid_t pid;
 
        ctx = xcalloc( sizeof(*ctx), 1 );
 
@@ -941,7 +942,10 @@ imap_open_store( imap_server_conf_t *srvc )
                        exit( 1 );
                }
 
-               if (fork() == 0) {
+               pid = fork();
+               if (pid < 0)
+                       _exit( 127 );
+               if (!pid) {
                        if (dup2( a[0], 0 ) == -1 || dup2( a[0], 1 ) == -1)
                                _exit( 127 );
                        close( a[0] );
@@ -1202,6 +1206,7 @@ read_message( FILE *f, msg_data_t *msg )
                        p = xrealloc(msg->data, len+1);
                        if (!p)
                                break;
+                       msg->data = p;
                }
                r = fread( &msg->data[msg->len], 1, len - msg->len, f );
                if (r <= 0)
@@ -1332,6 +1337,12 @@ main(int argc, char **argv)
                return 1;
        }
 
+       total = count_messages( &all_msgs );
+       if (!total) {
+               fprintf(stderr,"no messages to send\n");
+               return 1;
+       }
+
        /* write it to the imap server */
        ctx = imap_open_store( &server );
        if (!ctx) {
@@ -1339,7 +1350,6 @@ main(int argc, char **argv)
                return 1;
        }
 
-       total = count_messages( &all_msgs );
        fprintf( stderr, "sending %d message%s\n", total, (total!=1)?"s":"" );
        ctx->name = imap_folder;
        while (1) {