RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  j...@rpm5.org
  Module: rpm                              Date:   16-Jul-2016 16:41:28
  Branch: rpm-5_4                          Handle: 2016071614412800

  Modified files:           (Branch: rpm-5_4)
    rpm/rpmio               rpmmqtt.c rpmmqtt.h rpmpgp.h

  Log:
    - mqtt: clang-check -analyze clean.

  Summary:
    Revision    Changes     Path
    1.1.2.26    +211 -114   rpm/rpmio/rpmmqtt.c
    1.1.2.23    +2  -1      rpm/rpmio/rpmmqtt.h
    2.108.2.20  +2  -2      rpm/rpmio/rpmpgp.h
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmmqtt.c
  ============================================================================
  $ cvs diff -u -r1.1.2.25 -r1.1.2.26 rpmmqtt.c
  --- rpm/rpmio/rpmmqtt.c       14 Jul 2016 18:52:27 -0000      1.1.2.25
  +++ rpm/rpmio/rpmmqtt.c       16 Jul 2016 14:41:28 -0000      1.1.2.26
  @@ -76,8 +76,7 @@
        fprintf(fp, "fragment: %s\n", u->fragment);
        if (u->query) {
            ARGV_t av = NULL;
  -         int xx = argvSplit(&av, u->query, ",");
  -         (void)xx;
  +         (void) argvSplit(&av, u->query, ",");
            argvPrint(u->query, av, fp);
            av = argvFree(av);
        }
  @@ -228,8 +227,10 @@
       char *t = NULL;
       va_list ap;
   
  -    if (lhs && *lhs)
  -     *lhs = _free(*lhs);
  +    if (lhs && *lhs) {
  +     free(*lhs);
  +     *lhs = NULL;
  +    }
   
       va_start(ap, arg);
       t = vrpmMCExpand((mqtt ? mqtt->mc : NULL), arg, ap);
  @@ -517,10 +518,13 @@
        if (mqtt->ofd) {
            size_t nw;
            nw = Fwrite(topic, sizeof(*topic), topicLen, mqtt->ofd);
  +assert(nw > 0);
            nw = Fwrite(":\t", 1, sizeof(":\t")-1, mqtt->ofd);
  +assert(nw > 0);
            nw = Fwrite(s, sizeof(*s), ns, mqtt->ofd);
  +assert(nw > 0);
            nw = Fwrite("\n", 1, sizeof("\n")-1, mqtt->ofd);
  -         (void)nw;
  +assert(nw > 0);
        }
        break;
       }
  @@ -720,13 +724,16 @@
   
       *_mqttp = _mqtt;
   
  -    mqtt->cachedn = _free(mqtt->cachedn);
  +    if (mqtt->cachedn) {
  +     free((void *)mqtt->cachedn);
  +     mqtt->cachedn = NULL;
  +    }
       dn = rpmGetPath(mqtt->persist_path, "/", clientID, "-", serverURI, NULL);
       for (te = dn; (te = strchr(te, ':')) != NULL; te++)
        *te = '-';
   
       if (rpmioMkpath(dn, (mode_t)0740, (uid_t)-1, (gid_t)-1)) {
  -     dn = _free(dn);
  +     if (dn) free(dn);
        goto exit;
       }
       mqtt->cachedn = dn;
  @@ -821,7 +828,7 @@
       if (fd)
        Fclose(fd);
   SPEW((stderr, "<--    %s(%p,\"%s\",%d,%p,%p) rc %d fn %s\n", __FUNCTION__, 
_mqtt, key, bufcount, buffers, buflens, rc, fn));
  -    fn = _free(fn);
  +    if (fn) free(fn);
       return rc;
   }
   
  @@ -854,7 +861,7 @@
       fd = NULL;
   
       if (nb != nr) {
  -     b = _free(b);
  +     if (b) free(b);
        nb = 0;
        goto exit;
       }
  @@ -865,7 +872,7 @@
       if (fd)
        Fclose(fd);
   SPEW((stderr, "<--    %s(%p,\"%s\",%p,%p) rc %d fn %s\n", __FUNCTION__, 
_mqtt, key, buffer, buflen, rc, fn));
  -    fn = _free(fn);
  +    if (fn) free(fn);
       *buffer = b;
       *buflen = nb;
       return rc;
  @@ -889,7 +896,7 @@
   
   exit:
   SPEW((stderr, "<--    %s(%p,\"%s\") rc %d fn %s\n", __FUNCTION__, _mqtt, 
key, rc, fn));
  -    fn = _free(fn);
  +    if (fn) free(fn);
       return rc;
   }
   
  @@ -915,7 +922,7 @@
        if (Lstat(fn, &sb) == 0 && S_ISREG(sb.st_mode))
            (void) argvAdd(&av, dp->d_name);
        /* XXX strip .msg extension? */
  -     fn = _free(fn);
  +     if (fn) free(fn);
       }
       ac = argvCount(av);
       if (ac == 0)
  @@ -953,7 +960,7 @@
            if (Unlink(fn))
                nerrs++;
        }
  -     fn = _free(fn);
  +     if (fn) free(fn);
       }
   
       if (nerrs == 0)
  @@ -986,12 +993,12 @@
        if (Lstat(fn, &sb) == 0 && S_ISREG(sb.st_mode)) {
            /* XXX strip .msg extension? */
            if (!strcmp(dp->d_name, key)) {
  -             fn = _free(fn);
  +             if (fn) free(fn);
                rc = 0;
                goto exit;
            }
        }
  -     fn = _free(fn);
  +     if (fn) free(fn);
       }
   
   exit:
  @@ -1165,9 +1172,10 @@
   rpmRC pahoDestroy(rpmmqtt mqtt)
   {
       rpmRC rc = RPMRC_FAIL;   /* assume failure */
  -    rc = mqchk(mqtt, "destroy",
  +    (void) mqchk(mqtt, "destroy",
                (MQTTAsync_destroy(&mqtt->I), 0));
       mqtt->state = _free(mqtt->state);
  +    rc = RPMRC_OK;
       mqtt->I = NULL;
       return rc;
   }
  @@ -1178,14 +1186,17 @@
       static int oneshot;
       int _lvl = RPMLOG_DEBUG;
       rpmRC rc = RPMRC_FAIL;   /* assume failure */
  -    int xx;
   
       if (mqtt->I == NULL) {
        if (mqtt->trace && rpmIsDebug()) {
  -         xx = mqchk(mqtt, "setTraceCallback",
  +         rc = mqchk(mqtt, "setTraceCallback",
                (MQTTAsync_setTraceCallback(onTrace), 0));
  -         xx = mqchk(mqtt, "setTraceLevel",
  +         if (rc)
  +             goto exit;
  +         rc = mqchk(mqtt, "setTraceLevel",
                (MQTTAsync_setTraceLevel((enum 
MQTTASYNC_TRACE_LEVELS)mqtt->trace), 0));
  +         if (rc)
  +             goto exit;
        }
   
        rpmlog(_lvl, "==================== %s\n", mqtt->vec->name);
  @@ -1238,8 +1249,8 @@
        if (mqtt->trace)
            rpmlog(_lvl, "%19s: %d\n", "trace", mqtt->trace);
   
  -mqtt->persist_path = _free(mqtt->persist_path);
  -mqtt->persist_ctx = _free(mqtt->persist_ctx);
  +if (mqtt->persist_path) free((void *)mqtt->persist_path);
  +if (mqtt->persist_ctx) free((void *)mqtt->persist_ctx);
        switch (mqtt->persist_type) {
        default:
        case MQTTCLIENT_PERSISTENCE_NONE:
  @@ -1261,28 +1272,33 @@
            mqtt->persist_ctx = ctx;
          } break;
        }
  -persist_path = _free(persist_path);
  +if (persist_path) free(persist_path);
   
   #ifdef       DYING
   mqtt->u = NULL;
   dumpMQTT(__FUNCTION__, mqtt);
   #endif
   
  -     xx = mqchk(mqtt, "createWithOptions",
  +     rc = mqchk(mqtt, "createWithOptions",
                MQTTAsync_createWithOptions(&mqtt->I,
                        mqtt->uri, mqtt->clientid,
                        mqtt->persist_type, mqtt->persist_ctx,
                        (MQTTAsync_createOptions *)AOBJ(mqtt, 'O')));
  +     if (rc)
  +         goto exit;
   
  -     xx = mqchk(mqtt, "setCallbacks",
  +     rc = mqchk(mqtt, "setCallbacks",
                MQTTAsync_setCallbacks(mqtt->I, mqtt,
                        pahoOnConnectionLost,
                        pahoOnMessageArrived,
                        pahoOnDeliveryComplete));
  +     if (rc)
  +         goto exit;
       }
   
       rc = RPMRC_OK;
   
  +exit:
       return rc;
   }
   
  @@ -1631,10 +1647,13 @@
            size_t nw;
            nw = Fwrite(msg->topic, sizeof(*msg->topic), strlen(msg->topic),
                        mqtt->ofd);
  +assert(nw > 0);
            nw = Fwrite(":\t", 1, sizeof(":\t")-1, mqtt->ofd);
  +assert(nw > 0);
            nw = Fwrite(s, sizeof(*s), ns, mqtt->ofd);
  +assert(nw > 0);
            nw = Fwrite("\n", 1, sizeof("\n")-1, mqtt->ofd);
  -         (void)nw;
  +assert(nw > 0);
        }
        break;
       }
  @@ -1694,25 +1713,23 @@
       if (logtype & MOSQ_LOG_WEBSOCKETS)
        subsys = "websockets: ";
   
  -    rpmlog(RPMLOG_DEBUG, "%s: %s%s\n", mqtt->vec->name, subsys, str);
  +    rpmlog(lvl, "%s: %s%s\n", mqtt->vec->name, subsys, str);
   }
   
   static
   rpmRC mosqDestroy(rpmmqtt mqtt)
   {
       rpmRC rc = RPMRC_FAIL;   /* assume failure */
  -    int xx;
   #ifdef       NOTYET
       mqtt->state = _free(mqtt->state);
   #endif
       if (mqtt->I) {
  -
  -     xx = mqchk(mqtt, "loop_stop",
  +     (void) mqchk(mqtt, "loop_stop",
                mosquitto_loop_stop(mqtt->I, true));
  -
  -     xx = mqchk(mqtt, "destroy",
  +     (void) mqchk(mqtt, "destroy",
                (mosquitto_destroy(mqtt->I), 0));
       }
  +    rc = RPMRC_OK;
       mqtt->I = NULL;
       mosquitto_lib_cleanup();
       return rc;
  @@ -1724,7 +1741,6 @@
       rpmRC rc = RPMRC_FAIL;   /* assume failure */
       static int oneshot;
       int _lvl = RPMLOG_DEBUG;
  -    int xx;
   
       if (mqtt->I == NULL) {
   
  @@ -1736,8 +1752,10 @@
            int revision = 0;
            int version = 0;
   
  -         xx = mqchk(mqtt, "lib_init",
  +         rc = mqchk(mqtt, "lib_init",
                mosquitto_lib_init());
  +         if (rc)
  +             goto exit;
            version = mosquitto_lib_version(&major, &minor, &revision);
            rpmlog(_lvl, "%19s: %d.%d.%d (%d)\n", "version",
                        major, minor, revision, version);
  @@ -1756,10 +1774,12 @@
   dumpMQTT(__FUNCTION__, mqtt);
   #endif
   
  -     xx = mqchk(mqtt, "new",
  +     rc = mqchk(mqtt, "new",
                (mqtt->I = mosquitto_new(mqtt->clientid,
                        (MF_ISSET(CLEAN) ? true : false),
                        mqtt)) == NULL);
  +     if (rc)
  +         goto exit;
   
        mosquitto_connect_callback_set(mqtt->I, mosqOnConnect);
        mosquitto_disconnect_callback_set(mqtt->I, mosqOnDisconnect);
  @@ -1784,19 +1804,26 @@
    *      delay=3, delay_max=30, exponential_backoff=True
    *      Delays would be: 3, 6, 12, 24, 30, 30, ...
    */
  -     xx = mqchk(mqtt, "reconnect_delay_set",
  +     rc = mqchk(mqtt, "reconnect_delay_set",
                mosquitto_reconnect_delay_set(mqtt->I, 2, 10, false));
  +     if (rc)
  +         goto exit;
   
  -     xx = mqchk(mqtt, "user_data_set",
  +     rc = mqchk(mqtt, "user_data_set",
                (mosquitto_user_data_set(mqtt->I, mqtt), 0));
  +     if (rc)
  +         goto exit;
   
  -     xx = mqchk(mqtt, "loop_start",
  +     rc = mqchk(mqtt, "loop_start",
                mosquitto_loop_start(mqtt->I));
  +     if (rc)
  +         goto exit;
   
       }
   
       rc = RPMRC_OK;
   
  +exit:
       return rc;
   }
   
  @@ -1804,21 +1831,24 @@
   rpmRC mosqDisconnect(rpmmqtt mqtt)
   {
       rpmRC rc = RPMRC_FAIL;   /* assume failure */
  -    int xx;
   
       if (rpmmqttIsConnected(mqtt) == RPMRC_OK) {
   
  -     xx = mqchk(mqtt, "loop",
  +     rc = mqchk(mqtt, "loop",
                mosquitto_loop(mqtt->I, -1, 1));        /* XXX */
  +     if (rc)
  +         goto exit;
   
        mqtt->finished = 0;
        rc = mqchk(mqtt, "disconnect",
                mosquitto_disconnect(mqtt->I));
  +mqtt->connected = 0;
  +     if (rc)
  +         goto exit;
   
  -     xx = mqchk(mqtt, "loop",
  +     rc = mqchk(mqtt, "loop",
                mosquitto_loop(mqtt->I, -1, 1));
   
  -mqtt->connected = 0;
        if (rc)
            goto exit;
       }
  @@ -1832,7 +1862,6 @@
   rpmRC mosqConnect(rpmmqtt mqtt)
   {
       rpmRC rc = RPMRC_FAIL;   /* assume failure */
  -    int xx;
   
       if (rpmmqttIsConnected(mqtt) == RPMRC_NOTFOUND) {
        urlinfo u = mqtt->u;
  @@ -1841,59 +1870,75 @@
            const char *payload =
                (mqtt->will_message ? mqtt->will_message : "");
            int payloadlen = strlen(payload);
  -         xx = mqchk(mqtt, "will_set",
  +         rc = mqchk(mqtt, "will_set",
                mosquitto_will_set(mqtt->I,
                (mqtt->will_topic ? mqtt->will_topic : mqtt->topic),
                payloadlen, payload,
                mqtt->will_qos, /* XXX mqtt->qos? */
                (MF_ISSET(WILL_RETAIN) ? true : false)));
        } else
  -         xx = mqchk(mqtt, "will_clear",
  +         rc = mqchk(mqtt, "will_clear",
                mosquitto_will_clear(mqtt->I));
  +     if (rc)
  +         goto exit;
   
  -     xx = mqchk(mqtt, "username_pw_set",
  +     rc = mqchk(mqtt, "username_pw_set",
                mosquitto_username_pw_set(mqtt->I,
                        (u && u->user ? u->user : mqtt->user),
                        (u && u->password ? u->password : mqtt->password)));
  +     if (rc)
  +         goto exit;
   
        if (mqtt->cacertfile || mqtt->_capath) {
  -         xx = mqchk(mqtt, "tls_set",
  +         rc = mqchk(mqtt, "tls_set",
                    mosquitto_tls_set(mqtt->I,
                        mqtt->cacertfile, mqtt->_capath,
                        mqtt->certfile, mqtt->keyfile, mosqGetPassword));
  +         if (rc)
  +             goto exit;
        }
        if (MF_ISSET(INSECURE)) {
  -         xx = mqchk(mqtt, "tls_insecure_set",
  +         rc = mqchk(mqtt, "tls_insecure_set",
                    mosquitto_tls_insecure_set(mqtt->I, true));
  +         if (rc)
  +             goto exit;
        }
        if (mqtt->_psk_key) {
  -         xx = mqchk(mqtt, "tls_psk_set",
  +         rc = mqchk(mqtt, "tls_psk_set",
                    mosquitto_tls_psk_set(mqtt->I,
                        mqtt->_psk_key, mqtt->_psk_identity, NULL));
  +         if (rc)
  +             goto exit;
        }
        if (mqtt->ciphers && mqtt->_tls_version) {
            static int _cert_reqs = 1;  /* XXX 0/1: SSL_VERIFY_{NONE,PEER} */
            char * _tls_version = rpmExpand("tlsv", mqtt->_tls_version, NULL);
  -         xx = mqchk(mqtt, "tls_opts_set",
  +         rc = mqchk(mqtt, "tls_opts_set",
                mosquitto_tls_opts_set(mqtt->I,
                        _cert_reqs, _tls_version, mqtt->ciphers));
  -         _tls_version = _free(_tls_version);
  +         if (_tls_version) free(_tls_version);
  +         if (rc)
  +             goto exit;
        }
   
  -        xx = mqchk(mqtt, "max_inflight_messages_set",
  +        rc = mqchk(mqtt, "max_inflight_messages_set",
                mosquitto_max_inflight_messages_set(mqtt->I,
                        (mqtt->max_inflight ? mqtt->max_inflight : 20)));
  +     if (rc)
  +         goto exit;
   
        if (mqtt->_proxy) {
            urlinfo u;
            int ut = (urltype) urlSplit(mqtt->_proxy, &u);
            (void) ut;
  -         xx = mqchk(mqtt, "socks5_set",
  +         rc = mqchk(mqtt, "socks5_set",
                mosquitto_socks5_set(mqtt->I,
                        u->host,
                        u->port,
                        u->user,
                        u->password));
  +         if (rc)
  +             goto exit;
        }
   
        {   int MQTTVersion = MQTT_PROTOCOL_V31;
  @@ -1901,9 +1946,11 @@
                MQTTVersion = MQTT_PROTOCOL_V31;
            if (!strcmp(mqtt->protocol_version, "311"))
                MQTTVersion = MQTT_PROTOCOL_V311;
  -         xx = mqchk(mqtt, "opts_set",
  +         rc = mqchk(mqtt, "opts_set",
                mosquitto_opts_set(mqtt->I,
                        MOSQ_OPT_PROTOCOL_VERSION, &MQTTVersion));
  +         if (rc)
  +             goto exit;
        }
   
   #ifndef      NOTYET
  @@ -1921,8 +1968,11 @@
                        (u && u->host ? u->host : mqtt->host),
                        (u && u->host ? u->port : mqtt->port),
                        mqtt->keepalive));
  +     if (rc)
  +         goto exit;
        
  -#else
  +#else        /* NOTYET */
  +
        if (mqtt->_address) {
            if (MF_ISSET(DNSSRV)) {
                rc = mqchk(mqtt, "connect_srv",
  @@ -1942,9 +1992,9 @@
                        (u && u->host ? u->host : mqtt->host),
                        (u && u->host ? u->port : mqtt->port),
                        mqtt->keepalive));
  -#endif
  +#endif       /* NOTYET */
   
  -     xx = mqchk(mqtt, "loop",
  +     rc = mqchk(mqtt, "loop",
                mosquitto_loop(mqtt->I, -1, 1));
   
        if (rc)
  @@ -1969,7 +2019,6 @@
                const char * s, size_t ns)
   {
       rpmRC rc = RPMRC_FAIL;   /* assume failure */
  -    int xx;
   
       if (topic == NULL)
        topic = mqtt->topic;
  @@ -1988,13 +2037,14 @@
                        ns, s,
                        mqtt->qos,
                        (MF_ISSET(RETAIN) ? true : false)));
  +     if (rc)
  +         goto exit;
   
        rpmlog(RPMLOG_DEBUG, "%s: send(%d) topic(%s) \"%.*s\"\n",
                        mqtt->vec->name, mqtt->token, mqtt->topic, (int)ns, s);
   
  -     xx = mqchk(mqtt, "loop",
  +     rc = mqchk(mqtt, "loop",
                mosquitto_loop(mqtt->I, -1, 1));
  -
        if (rc)
            goto exit;
        rc = RPMRC_OK;
  @@ -2008,7 +2058,6 @@
   rpmRC mosqSubscribe(rpmmqtt mqtt, const char * topic, int qos)
   {
       rpmRC rc = RPMRC_FAIL;   /* assume failure */
  -    int xx;
   
       if (!rpmmqttConnect(mqtt)) {
   
  @@ -2020,8 +2069,10 @@
                        (int *)&mqtt->token,
                        (topic ? topic : mqtt->topic),
                        qos));
  +     if (rc)
  +         goto exit;
   
  -     xx = mqchk(mqtt, "loop",
  +     rc = mqchk(mqtt, "loop",
                mosquitto_loop(mqtt->I, -1, 1));
   
        if (rc)
  @@ -2037,7 +2088,6 @@
   rpmRC mosqUnsubscribe(rpmmqtt mqtt, const char * topic)
   {
       rpmRC rc = RPMRC_FAIL;   /* assume failure */
  -    int xx;
   
       if (!rpmmqttConnect(mqtt)) {
   
  @@ -2048,8 +2098,10 @@
                mosquitto_unsubscribe(mqtt->I,
                        (int *)&mqtt->token,
                        (topic ? topic : mqtt->topic)));
  +     if (rc)
  +         goto exit;
   
  -     xx = mqchk(mqtt, "loop",
  +     rc = mqchk(mqtt, "loop",
                mosquitto_loop(mqtt->I, -1, 1));
   
        if (rc)
  @@ -2335,6 +2387,8 @@
   
        rc = mqchk(mqtt, "new_connection",
                ((mqtt->I = amqp_new_connection()) == NULL));
  +     if (rc)
  +         goto exit;
   
        if (mqtt->cacertfile || mqtt->_capath) {
            port = mqtt->vec->sport;    /* XXX elsewhere */
  @@ -2346,13 +2400,19 @@
     amqp_ssl_socket_set_verify_peer(socket, 1);
     amqp_ssl_socket_set_verify_hostname(socket, 1);
   #endif
  -         if (mqtt->cacertfile)
  +         if (mqtt->cacertfile) {
                rc = mqchk(mqtt, "ssl_socket_set_cacert",
                        amqp_ssl_socket_set_cacert(mqtt->I, mqtt->cacertfile));
  -         if (mqtt->keyfile)
  +             if (rc)
  +                 goto exit;
  +         }
  +         if (mqtt->keyfile) {
                rc = mqchk(mqtt, "ssl_socket_set_key",
                        amqp_ssl_socket_set_key(mqtt->I,
                                mqtt->certfile, mqtt->keyfile));
  +             if (rc)
  +                 goto exit;
  +         }
        } else {
            port = mqtt->vec->port;     /* XXX elsewhere */
            rc = mqchk(mqtt, "tcp_socket_new",
  @@ -2434,13 +2494,15 @@
            goto exit;
   
        amqp_channel_open_ok_t * open_ok = NULL;
  +     (void)open_ok;
        amqp_channel_t _channel = 1;
        rc = mqchk(mqtt, "channel_open",
                ((open_ok = amqp_channel_open(mqtt->I, _channel)),
                0));
  +     if (rc)
  +         goto exit;
        rc = mqchkrpc(mqtt, "get_rpc_reply",
                amqp_get_rpc_reply(mqtt->I));
  -
        if (rc)
            goto exit;
   mqtt->connected = 1;
  @@ -2489,6 +2551,7 @@
        _properties = &props;
   #endif
   
  +fprintf(stderr, "*** %s: %s mqtt host %s topic %s\n", __FUNCTION__, topic, 
mqtt->host, mqtt->topic);
        rc = mqchk(mqtt, "basic_publish",
                amqp_basic_publish(mqtt->I,
                                _channel,
  @@ -2723,13 +2786,14 @@
   {
       rpmRC rc = RPMRC_FAIL;   /* assume failure */
       if (mqtt->I) {
  -     rc = mqchk(mqtt, "messenger_stop",
  +     (void) mqchk(mqtt, "messenger_stop",
                pn_messenger_stop(mqtt->I));
  -     rc = mqchk(mqtt, "messenger_free",
  +     (void) mqchk(mqtt, "messenger_free",
                (pn_messenger_free(mqtt->I),0));
  -     rc = mqchk(mqtt, "message_free",
  +     (void) mqchk(mqtt, "message_free",
                (pn_message_free(mqtt->M),0));
       }
  +    rc = RPMRC_OK;   /* XXX */
       mqtt->I = NULL;
       return rc;
   }
  @@ -2770,12 +2834,17 @@
   
            rc = mqchk(mqtt, "messenger",
                ((mqtt->I = pn_messenger(NULL)) == NULL));
  +         if (rc)
  +             goto exit;
            rc = mqchk(mqtt, "messenger_start",
                pn_messenger_start(mqtt->I));
  +         if (rc)
  +             goto exit;
       }
   
       rc = RPMRC_OK;
   
  +exit:
       return rc;
   }
   
  @@ -2835,17 +2904,22 @@
                goto exit;
        }
   
  -
  -fprintf(stderr, "*** %s: host %s topic %s\n", __FUNCTION__, mqtt->host, 
mqtt->topic);
  +fprintf(stderr, "*** %s: %s mqtt host %s topic %s\n", __FUNCTION__, topic, 
mqtt->host, mqtt->topic);
        const char * _address = "amqp://localhost/test";        /* XXX */
        rc = mqchk(mqtt, "message_set_address",
                pn_message_set_address(mqtt->M, _address));
  +     if (rc)
  +         goto exit;
   
        {   pn_data_t * body = pn_message_body(mqtt->M);
            rc = mqchk(mqtt, "data_put_string",
                        pn_data_put_string(body, pn_bytes(ns, s)));
  +         if (rc)
  +             goto exit;
            rc = mqchk(mqtt, "messenger_put",
                        pn_messenger_put(mqtt->I, mqtt->M));
  +         if (rc)
  +             goto exit;
   #ifdef       NOTYET
            check(messenger);
   #endif
  @@ -3062,7 +3136,7 @@
        ns = strlen(s);
   
       if (!rpmmqttConnect(mqtt)) {
  -fprintf(stderr, "XXX %s: FIXME\n", __FUNCTION__);
  +fprintf(stderr, "XXX %s: FIXME: %s %*.s\n", __FUNCTION__, topic, (int)ns, s);
        if (rc)
            goto exit;
        rc = RPMRC_OK;
  @@ -3159,7 +3233,7 @@
        size_t nt = strlen(t);
   
        rc = rpmmqttSendMessage(mqtt, topic, t, nt);
  -     t = _free(t);
  +     if (t) free(t);
        if (rc)
            goto exit;
        rc = RPMRC_OK;
  @@ -3210,7 +3284,7 @@
   
        rc = rpmmqttSubscribe(mqtt, subtopic, subqos);
   
  -     subtopic = _free(subtopic);
  +     if (subtopic) free(subtopic);
        if (rc)
            goto exit;
        rc = RPMRC_OK;
  @@ -3340,7 +3414,7 @@
     struct poptOption rpmmqttOptionsTable[] = {
      { "buffer", 'b', POPT_BIT_SET,    &mqtt->flags, MQTT_FLAGS_BUFFER,
        N_("Collect input messages in buffer."), NULL },
  -   { "debug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmmqtt_debug, -1,
  +   { "debug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &mqtt->debug, -1,
        N_("Debug spewage."), NULL },
      { "file", 'f', POPT_ARG_ARGV,     &mqtt->ifn, 0,
        N_("Send <FILE> as message."), N_("<FILE>") },
  @@ -3383,7 +3457,7 @@
     };
       static int _popt_context_flags = 0; /* XXX POPT_CONTEXT_POSIXMEHARDER */
       poptContext con = NULL;
  -    rpmRC rc = RPMRC_FAIL;      /* assume failure */
  +    rpmRC rc;
       int xx;
   
   SPEW((stderr, "--> %s(%p,%p[%d])\n", __FUNCTION__, mqtt, av, ac));
  @@ -3396,19 +3470,18 @@
       default:
        fprintf(stderr, _("%s: option table misconfigured (%d)\n"),
                   __FUNCTION__, xx);
  -     goto exit;
  +assert(xx == 0);
        break;
       }
   
       mqtt->av = NULL;
  -    xx = argvAppend((ARGV_t *)&mqtt->av, poptGetArgs(con));
  +    (void) argvAppend((ARGV_t *)&mqtt->av, poptGetArgs(con));
   
       mqtt->ac = argvCount((ARGV_t)mqtt->av);
       rc = RPMRC_OK;
   
  -exit:
       if (con)
  -     con = poptFreeContext(con);
  +     (void) poptFreeContext(con);
   
   SPEW((stderr, "<-- %s(%p,%p[%d]) rc %d\n", __FUNCTION__, mqtt, av, ac, rc));
       return rc;
  @@ -3500,8 +3573,8 @@
       /* XXX rpmExpand() ??? */
   #define      URIQUERY_SET_STR(OPT, VAL)                              \
       if (!strncmp(t, #OPT, (te - t))) {                               \
  -     mqtt->OPT = _free(mqtt->OPT);                   \
  -     mqtt->OPT = xstrdup(te[0] == '=' ? te+1 : VAL); \
  +     if (mqtt->OPT) free((void *)mqtt->OPT);                         \
  +     mqtt->OPT = xstrdup(te[0] == '=' ? te+1 : VAL);         \
        continue;                                               \
       }
   
  @@ -3531,7 +3604,7 @@
       }
   #define      URIQUERY_SET_STR(OPT, VAL)                              \
       if (!strncmp(t, #OPT, (te - t))) {                               \
  -     mqtt->_##OPT = _free(mqtt->_##OPT);                     \
  +     if (mqtt->_##OPT) free((void *)mqtt->_##OPT);                   \
        mqtt->_##OPT = xstrdup(te[0] == '=' ? te+1 : VAL);      \
        continue;                                               \
       }
  @@ -3562,7 +3635,9 @@
       ARGV_t av = NULL;
       int ac;
       const char *t;
  +#ifdef       UNUSED
       const char *te;
  +#endif
       rpmRC rc = RPMRC_OK;
   
       /* https://en.wikipedia.org/wiki/Fragment_identifier */
  @@ -3574,13 +3649,16 @@
   #ifdef       DYING
   argvPrint(__FUNCTION__, av, NULL);
   #endif
  +
       ac = argvCount(av);
       for (int i = 0; i < ac; i++) {
        t = av[i];
        if (!(t && *t))
            continue;
  +#ifdef       UNUSED
        if ((te = strchr(t, '=')) == NULL)
            te += strlen(t);
  +#endif
        (void) argvAdd(&mqtt->subtopics, t);
       }
       av = argvFree(av);
  @@ -3606,22 +3684,22 @@
        || !strcmp(u->scheme, "mqtts"))
       {
        if (u->portstr == NULL) {
  -         u->portstr = !strcmp(u->scheme, "mqtts")
  +         u->portstr = u->scheme && !strcmp(u->scheme, "mqtts")
                ? xstrdup("8883") : xstrdup("1883");
        
        }
       }
   
       if (u->user != NULL) {
  -mqtt->user = _free(mqtt->user);
  +if (mqtt->user) free((void *)mqtt->user);
        mqtt->user = xstrdup(u->user);
       }
       if (u->password != NULL) {
  -mqtt->password = _free(mqtt->password);
  +if (mqtt->password) free((void *)mqtt->password);
        mqtt->password = xstrdup(u->password);
       }
       if (u->host != NULL) {
  -mqtt->host = _free(mqtt->host);
  +if (mqtt->host) free((void *)mqtt->host);
        mqtt->host = xstrdup(u->host);
       }
       if (u->portstr != 0) {   /* XXX u->port? */
  @@ -3662,12 +3740,13 @@
   SPEW((stderr, "--> %s(%p,%p[%d],0x%x)\n", __FUNCTION__, mqtt, av, ac, 
flags));
   
       static mqttFlags _flags = MQTT_FLAGS_DEFAULT;    /* CLEAN|EOL */
  +assert(mqtt);
       mqtt->flags = (flags ? flags : _flags);
   
       /* -- Set module vector and program name/mode from av[0] */
   assert(av && av[0]);
  -mqtt->_progname = _free(mqtt->_progname);
  -mqtt->_progmode = _free(mqtt->_progmode);
  +if (mqtt->_progname) free((void *)mqtt->_progname);
  +if (mqtt->_progmode) free((void *)mqtt->_progmode);
       {        const char *arg0 = av[0];
        const char * _progname;
        const char * _progmode;
  @@ -3795,7 +3874,7 @@
       rc = RPMRC_OK;
   
   exit:
  -    uri = _free(uri);
  +    if (uri) free((void *)uri);
   SPEW((stderr, "<-- %s(%p,%p[%d],0x%x) rc %d\n", __FUNCTION__, mqtt, av, ac, 
flags, rc));
       return rc;
   }
  @@ -3804,16 +3883,15 @@
   {
       rpmRC rc = RPMRC_FAIL;   /* assume failure */
       int nsubs = 0;
  -    int xx;
   
   #ifdef       DYING
   argvPrint(__FUNCTION__, (ARGV_t)topics, NULL);
   #endif
       if (topics) {
        nsubs = argvCount((ARGV_t)topics);
  -     xx = rpmmqttSubscribeMany(mqtt, nsubs, (char **)topics);
  -    }
  -    rc = RPMRC_OK;
  +     rc = rpmmqttSubscribeMany(mqtt, nsubs, (char **)topics);
  +    } else
  +     rc = RPMRC_OK;
   SPEW((stderr, "<-- %s(%p,%p[%d]) rc %d\n", __FUNCTION__, mqtt, topics, 
nsubs, rc));
       return rc;
   }
  @@ -3831,7 +3909,6 @@
       ARGV_t lav = NULL;
       int lac = 0;
       rpmRC rc = RPMRC_FAIL;   /* assume failure */
  -    int xx;
   
       switch (mqtt->msg_input) {
       case MQTT_INPUT_UNKNOWN:
  @@ -3842,12 +3919,16 @@
            s = mqtt->msgs[i];
            ns = strlen(s);
            if (ntopics <= 0)
  -             xx = rpmmqttPub(mqtt, topic, s, ns);
  +             rc = rpmmqttPub(mqtt, topic, s, ns);
            else
            for (int j = 0; j < ntopics; j++) {
                topic = topics[j];
  -             xx = rpmmqttPub(mqtt, topic, s, ns);
  +             rc = rpmmqttPub(mqtt, topic, s, ns);
  +             if (rc)
  +                 break;
            }
  +         if (rc)
  +             goto exit;
        }
        break;
       case MQTT_INPUT_FILES:
  @@ -3860,12 +3941,16 @@
                if (ns == 0)    /* XXX skip empty files? */
                    continue;
                if (ntopics <= 0)
  -                 xx = rpmmqttPub(mqtt, topic, s, ns);
  +                 rc = rpmmqttPub(mqtt, topic, s, ns);
                else
                for (int j = 0; j < ntopics; j++) {
                    topic = topics[j];
  -                 xx = rpmmqttPub(mqtt, topic, s, ns);
  +                 rc = rpmmqttPub(mqtt, topic, s, ns);
  +                 if (rc)
  +                     break;
                }
  +             if (rc)
  +                 goto exit;
            }
            iob = rpmiobFree(iob);
        }
  @@ -3874,7 +3959,7 @@
        for (int i = 0; i < nifn; i++) {
            ifn = mqtt->ifn[i];
            if (rpmiobSlurp(ifn, &iob) == 0) {
  -             xx = argvSplit(&lav, rpmiobStr(iob), "\n\r");
  +             rc = argvSplit(&lav, rpmiobStr(iob), "\n\r");
                lac = argvCount(lav);
                for (int j = 0; j < lac; j++) {
                    s = lav[j];
  @@ -3883,12 +3968,16 @@
                    if (ns == 0)        /* XXX skip empty lines? */
                        continue;
                    if (ntopics <= 0)
  -                     xx = rpmmqttPub(mqtt, topic, s, ns);
  +                     rc = rpmmqttPub(mqtt, topic, s, ns);
                    else
                    for (int k = 0; j < ntopics; j++) {
                        topic = topics[k];
  -                     xx = rpmmqttPub(mqtt, topic, s, ns);
  +                     rc = rpmmqttPub(mqtt, topic, s, ns);
  +                     if (rc)
  +                         break;
                    }
  +                 if (rc)
  +                     goto exit;
                }
                lav = argvFree(lav);
            }
  @@ -3897,6 +3986,7 @@
        break;
       }
       rc = RPMRC_OK;
  +exit:
       return rc;
   }
   
  @@ -3908,7 +3998,7 @@
       (void) rpmmqttDisconnect(mqtt);
       (void) rpmmqttDestroy(mqtt);
   
  -#define      FINI_FREE(VAR)          { mqtt->VAR = _free(mqtt->VAR); }
  +#define      FINI_FREE(VAR)          { if (mqtt->VAR) free((void 
*)mqtt->VAR); }
   #define      FINI_FREE_ARGV(VAR)     { mqtt->VAR = 
argvFree((ARGV_t)mqtt->VAR); }
   /* ========== */
       FINI_FREE(_progname)
  @@ -4000,14 +4090,14 @@
       int ac = argvCount((ARGV_t)av);
       flags &= ~0x80000000;
       rpmRC rc = rpmmqttInit(mqtt, ac, (const char **)av, (mqttFlags)flags);
  -    (void)rc;
  +if (rc) fprintf(stderr, "*** %s:%u rc %d\n", __FUNCTION__, __LINE__, rc);
   assert(mqtt->_progname);
   assert(mqtt->_progmode);
   
       {
  -     int xx;
   
  -     xx = rpmmqttCreate(mqtt);
  +     rc = rpmmqttCreate(mqtt);
  +if (rc) fprintf(stderr, "*** %s:%u rc %d\n", __FUNCTION__, __LINE__, rc);
   
        /* Prepare for subscription delivery. */
        if (MF_ISSET(BUFFER) && mqtt->iob == NULL)
  @@ -4050,7 +4140,7 @@
                }
            }
            if (bingo) {
  -             mqtt->_progmode = _free(mqtt->_progmode);
  +             if (mqtt->_progmode) free((void *)mqtt->_progmode);
                mqtt->_progmode = xstrdup("sub");
            }
        }
  @@ -4058,10 +4148,15 @@
        /* Execute in either "sub" or "pub" mode. */
        if (mqtt->_progmode && !strcmp(mqtt->_progmode, "sub")) {
            /* Subscribe to topics (if any). */
  -         if (mqtt->topic)
  -             xx = rpmmqttSub(mqtt, mqtt->topic, strlen(mqtt->topic));
  -         xx = rpmmqttInitSubscribe(mqtt, mqtt->subtopics);
  -         xx = rpmmqttInitSubscribe(mqtt, mqtt->topics);
  +         if (mqtt->topic) {
  +             rc = rpmmqttSub(mqtt, mqtt->topic, strlen(mqtt->topic));
  +if (rc) fprintf(stderr, "*** %s:%u rc %d\n", __FUNCTION__, __LINE__, rc);
  +         }
  +
  +         rc = rpmmqttInitSubscribe(mqtt, mqtt->subtopics);
  +if (rc) fprintf(stderr, "*** %s:%u rc %d\n", __FUNCTION__, __LINE__, rc);
  +         rc = rpmmqttInitSubscribe(mqtt, mqtt->topics);
  +if (rc) fprintf(stderr, "*** %s:%u rc %d\n", __FUNCTION__, __LINE__, rc);
   
            /* Wait for messages ... */
            while (mqtt->max_msg_count <= 0
  @@ -4071,10 +4166,12 @@
            }
        } else {
            /* Subscribe to initial topics (if any). */
  -         xx = rpmmqttInitSubscribe(mqtt, mqtt->subtopics);
  +         rc = rpmmqttInitSubscribe(mqtt, mqtt->subtopics);
  +if (rc) fprintf(stderr, "*** %s:%u rc %d\n", __FUNCTION__, __LINE__, rc);
   
            /* Publish any initial messages (if any). */
  -         xx = rpmmqttInitPublish(mqtt, mqtt->topics);
  +         rc = rpmmqttInitPublish(mqtt, mqtt->topics);
  +if (rc) fprintf(stderr, "*** %s:%u rc %d\n", __FUNCTION__, __LINE__, rc);
        }
       }
   
  @@ -4102,7 +4199,7 @@
       }
   
   exit:
  -    msg = _free(msg);
  +    if (msg) free((void *)msg);
   SPEW((stderr, "<== %s(%p,\"%s\",%p) rc %d\n", __FUNCTION__, mqtt, str, 
resultp, rc));
       return rc;
   }
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmmqtt.h
  ============================================================================
  $ cvs diff -u -r1.1.2.22 -r1.1.2.23 rpmmqtt.h
  --- rpm/rpmio/rpmmqtt.h       14 Jul 2016 18:52:27 -0000      1.1.2.22
  +++ rpm/rpmio/rpmmqtt.h       16 Jul 2016 14:41:28 -0000      1.1.2.23
  @@ -64,7 +64,8 @@
   
   #if defined(_RPMMQTT_INTERNAL)
   
  -#define SPEW(_list)     if (mqtt->debug || _rpmmqtt_debug < 0) fprintf _list
  +#define SPEW(_list) \
  +     if ((mqtt && mqtt->debug) || _rpmmqtt_debug < 0) fprintf _list
   
   struct rpmmqtt_s {
       struct rpmioItem_s _item;        /*!< usage mutex and pool identifier. */
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmpgp.h
  ============================================================================
  $ cvs diff -u -r2.108.2.19 -r2.108.2.20 rpmpgp.h
  --- rpm/rpmio/rpmpgp.h        25 Jun 2016 07:31:08 -0000      2.108.2.19
  +++ rpm/rpmio/rpmpgp.h        16 Jul 2016 14:41:28 -0000      2.108.2.20
  @@ -1087,7 +1087,7 @@
       static size_t nb = sizeof(prbuf) - 32;
       char *t = prbuf;
       unsigned ui = (plen <= nb) ? plen : nb;
  -    t = pgpHexCvt(t, p, ui);
  +    (void) pgpHexCvt(t, p, ui);
       return prbuf;
   }
   
  @@ -1108,7 +1108,7 @@
       t += strlen(t);
       if ((ui = pgpMpiLen(p)) > nb)
        ui = nb;
  -    t = pgpHexCvt(t, p+2, ui-2);
  +    (void) pgpHexCvt(t, p+2, ui-2);
       return prbuf;
   }
   
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org

Reply via email to