ctdb/docs: Include ceph rados namespace support in man page
[samba.git] / source3 / registry / reg_perfcount.c
index a8f76ac66b217ff5709fd211ff2618dff21a22be..131cc57d9587721ac61ff66f1601ab6542e4333c 100644 (file)
@@ -48,7 +48,7 @@ static char *counters_directory(const char *dbname)
        char *db_subpath = NULL;
        char *ret = NULL;
 
-       dir_path = state_path(PERFCOUNTDIR);
+       dir_path = state_path(talloc_tos(), PERFCOUNTDIR);
        if (dir_path == NULL) {
                return NULL;
        }
@@ -64,7 +64,7 @@ static char *counters_directory(const char *dbname)
                return NULL;
        }
 
-       ret = state_path(db_subpath);
+       ret = state_path(talloc_tos(), db_subpath);
        TALLOC_FREE(dir_path);
        return ret;
 }
@@ -166,13 +166,13 @@ static uint32_t _reg_perfcount_multi_sz_from_tdb(TDB_CONTEXT *tdb,
                                               uint32_t buffer_size)
 {
        TDB_DATA kbuf, dbuf;
-       char temp[256];
+       char temp[PERFCOUNT_MAX_LEN] = {0};
        char *buf1 = *retbuf;
+       char *p = NULL;
        uint32_t working_size = 0;
        DATA_BLOB name_index, name;
        bool ok;
 
-       memset(temp, 0, sizeof(temp));
        snprintf(temp, sizeof(temp), "%d", keyval);
        kbuf = string_tdb_data(temp);
        dbuf = tdb_fetch(tdb, kbuf);
@@ -186,13 +186,16 @@ static uint32_t _reg_perfcount_multi_sz_from_tdb(TDB_CONTEXT *tdb,
        }
        /* First encode the name_index */
        working_size = (kbuf.dsize + 1)*sizeof(uint16_t);
-       buf1 = (char *)SMB_REALLOC(buf1, buffer_size + working_size);
-       if(!buf1) {
+       /* SMB_REALLOC frees buf1 on error */
+       p = (char *)SMB_REALLOC(buf1, buffer_size + working_size);
+       if (p == NULL) {
                buffer_size = 0;
                return buffer_size;
        }
+       buf1 = p;
        ok = push_reg_sz(talloc_tos(), &name_index, (const char *)kbuf.dptr);
        if (!ok) {
+               SAFE_FREE(buf1);
                buffer_size = 0;
                return buffer_size;
        }
@@ -200,16 +203,19 @@ static uint32_t _reg_perfcount_multi_sz_from_tdb(TDB_CONTEXT *tdb,
        buffer_size += working_size;
        /* Now encode the actual name */
        working_size = (dbuf.dsize + 1)*sizeof(uint16_t);
-       buf1 = (char *)SMB_REALLOC(buf1, buffer_size + working_size);
-       if(!buf1) {
+       /* SMB_REALLOC frees buf1 on error */
+       p = (char *)SMB_REALLOC(buf1, buffer_size + working_size);
+       if (p == NULL) {
                buffer_size = 0;
                return buffer_size;
        }
+       buf1 = p;
        memset(temp, 0, sizeof(temp));
        memcpy(temp, dbuf.dptr, dbuf.dsize);
        SAFE_FREE(dbuf.dptr);
        ok = push_reg_sz(talloc_tos(), &name, temp);
        if (!ok) {
+               SAFE_FREE(buf1);
                buffer_size = 0;
                return buffer_size;
        }
@@ -709,13 +715,13 @@ static bool _reg_perfcount_get_instance_info(struct PERF_INSTANCE_DEFINITION *in
                                             TDB_CONTEXT *names)
 {
        TDB_DATA key, data;
-       char buf[PERFCOUNT_MAX_LEN], temp[PERFCOUNT_MAX_LEN];
+       char buf[PERFCOUNT_MAX_LEN] = {0};
+       char temp[32] = {0};
        smb_ucs2_t *name = NULL;
        int pad;
 
        /* First grab the instance data from the data file */
-       memset(temp, 0, PERFCOUNT_MAX_LEN);
-       snprintf(temp, PERFCOUNT_MAX_LEN, "i%d", instId);
+       snprintf(temp, sizeof(temp), "i%d", instId);
        _reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, obj->ObjectNameTitleIndex, temp);
        if (!_reg_perfcount_get_counter_data(key, &data)) {
                DEBUG(3, ("_reg_perfcount_get_counter_data failed\n"));
@@ -739,8 +745,7 @@ static bool _reg_perfcount_get_instance_info(struct PERF_INSTANCE_DEFINITION *in
        SAFE_FREE(data.dptr);
 
        /* Fetch instance name */
-       memset(temp, 0, PERFCOUNT_MAX_LEN);
-       snprintf(temp, PERFCOUNT_MAX_LEN, "i%dname", instId);
+       snprintf(temp, sizeof(temp), "i%dname", instId);
        _reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, obj->ObjectNameTitleIndex, temp);
        data = tdb_fetch(names, key);
        if(data.dptr == NULL)
@@ -1395,7 +1400,7 @@ static bool _reg_perfcount_marshall_perf_objects(prs_struct *ps, struct PERF_DAT
 
                /* Now do the counters */
                /* If no instances, encode counter_data */
-               /* If instances, encode instace plus counter data for each instance */
+               /* If instances, encode instance plus counter data for each instance */
                if(_reg_perfcount_marshall_perf_counters(ps, object, depth) == False)
                        return False;
                if(object.NumInstances == PERF_NO_INSTANCES)