Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socket.c improvements and unit tests #914

Merged
merged 5 commits into from
Jun 1, 2022

Conversation

cfconrad
Copy link
Collaborator

This PR is the second outcome of (bsc#1192508) and the continues work started with
#912 .
The src/socket.c module had some possible issues in special cases, which solved with
these changes. To avoid regressions, I created a unit test suit for that module, which show the issues in
the old implementation.
Also some code cleanup in dbus was added, where we had wrong refcount handling of ni_socket_t objects.

When ever we do not care of a ni_socket_t object, we need to call the
ni_socket_release(), otherwise the reference will kept forever.
@cfconrad cfconrad force-pushed the wip-memory-curruption-2 branch 2 times, most recently from c2aaac6 to 6c0a08b Compare May 30, 2022 08:39
Copy link
Member

@mtomaschewski mtomaschewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testing: Run tests within valgrind mem-check

To do so, we use the automake `test-driver` and adopt it
to the functionality of valgrind.

But it does not provide the test-driver with --valgrind support any more.

  • After a make check run, there are untracked files:
Untracked files:
  (use "git add <file>..." to include in what will be committed)
	testing/socket-mock-test.log
	testing/socket-mock-test.trs
	testing/test-suite.log

nothing added to commit but untracked files present (use "git add" to track)

In ni_socket_array_wait() we should not manipulating the same array
what we use for iteration.
The static socket array __ni_sockets should not be used for iteration,
as we might manipulate the array via ni_socket_close() from other
modules.
The close() callback was called unconditional, thus it got called
even if the file descriptor is already unset.
If a `ni_socket_release()` is called with a refcount equal to `1`,
we hit a assert in a recursive call of ni_socket_release().

Simply check that no one call `ni_socket_release()` on the last
reference, while the socket is still active!
Cover upcoming regressions and check for issues in corner cases
which failed in old implementation.
@cfconrad
Copy link
Collaborator Author

Good catch.
Last changes should avoid these and also the test-driver should be there.

@mtomaschewski mtomaschewski self-requested a review May 31, 2022 18:29
mtomaschewski
mtomaschewski previously approved these changes May 31, 2022
Copy link
Member

@mtomaschewski mtomaschewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... almost. It works fine now... except of the fact, that autogen.sh (autoreconf) overwrites the test-driver with the --valgrind=yes/no addition...:

$ git status
On branch pull-914-3
Your branch is up to date with 'github/pull/914/head'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   test-driver

no changes added to commit (use "git add" and/or "git commit -a")
$ git diff
diff --git a/test-driver b/test-driver
index db1a2378..d86cf694 100755
--- a/test-driver
+++ b/test-driver
@@ -1,8 +1,9 @@
-#!/bin/sh
+#! /bin/sh
 # test-driver - basic testsuite driver script.
-#
+
+scriptversion=2016-01-11.22; # UTC
+
 # Copyright (C) 2011-2017 Free Software Foundation, Inc.
-# Copyright (C) 2022 SUSE LLC
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
[...]

@mtomaschewski
Copy link
Member

@cfconrad Perhaps we should use the standard test-driver first and take a separate / deeper look at e.g.:

later?

@cfconrad
Copy link
Collaborator Author

urgs, I didn't realized it, sorry!
Yes I think so too, I removed d2e04e2 from this PR.
This https://www.gnu.org/software/autoconf-archive/ax_valgrind_check.html looks very promising! Thanks for the pointer!

Copy link
Member

@mtomaschewski mtomaschewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, then lets merge it.

@mtomaschewski mtomaschewski merged commit cd308dc into openSUSE:master Jun 1, 2022
@cfconrad cfconrad deleted the wip-memory-curruption-2 branch September 19, 2022 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants