diff --git a/src/cats/sql_find.c b/src/cats/sql_find.c index ef716b820a3..c354c8a984c 100644 --- a/src/cats/sql_find.c +++ b/src/cats/sql_find.c @@ -435,9 +435,18 @@ int db_find_next_volume(JCR *jcr, B_DB *mdb, int item, bool InChanger, MEDIA_DBR } /* - * See if this is not on the unwanted volumes list. + * Skip if volume is on unwanted volumes list. + * We need to reduce the number of rows by one + * and jump out if no more rows are available */ if (unwanted_volumes && is_on_unwanted_volumes_list(row[1], unwanted_volumes)) { + Dmsg1(50, "Volume %s is on unwanted_volume_list, skipping\n", row[1]); + num_rows-- ; + if ( num_rows <= 0) { + Dmsg1(50, "No more volumes in result, bailing out\n", row[1]); + sql_free_result(mdb); + goto bail_out; + } continue; }