rrdtool-1.x icon indicating copy to clipboard operation
rrdtool-1.x copied to clipboard

Could write_changes_to_disk be called twice?

Open yli-cpr opened this issue 5 years ago • 4 comments

Just noticed this while reading the source code. When HAVE_LIBRADOS is true and HAVE_MMAP is false, write_changes_to_disk could be called twice?

#ifdef HAVE_LIBRADOS
    if (rrd_file->rados)
      write_changes_to_disk(&rrd, rrd_file, version);
#endif
#ifndef HAVE_MMAP
    if (write_changes_to_disk(&rrd, rrd_file, version) == -1) {
        goto err_free_structures;
    }
#endif

yli-cpr avatar Sep 20 '19 17:09 yli-cpr

oh ... indeed ... can you PR ?

oetiker avatar Sep 23 '19 07:09 oetiker

I would. But I really know nothing about rrdtool, and don't have a test environment either. I am not certain what a correct fix here. Will this be good?

#if defined(HAVE_LIBRADOS)
      ...
#elif not defined(HAVE_MMAP)
     ...
#endif 

yli-cpr avatar Sep 27 '19 12:09 yli-cpr

how about this:

#ifdef HAVE_LIBRADOS
    if (rrd_file->rados) {
       if (write_changes_to_disk(&rrd, rrd_file, version) == -1) {
          goto err_free_structures;
       }
    }
#ifndef HAVE_MMAP
    else
#endif
#endif
#ifndef HAVE_MMAP
    if (write_changes_to_disk(&rrd, rrd_file, version) == -1) {
        goto err_free_structures;
    }
#endif

oetiker avatar Sep 27 '19 20:09 oetiker

Pull request created: https://github.com/oetiker/rrdtool-1.x/pull/1059

yli-cpr avatar Sep 30 '19 12:09 yli-cpr